Using a 2D array for the first time for my university project.
im struggling on how to place a user entered value into a specific slot in the array.
what i do have is.
cout << "Enter Number of Groups" << endl;
cin >> DefinedGroups;
int user_groups[definedgroups] [2]
while (havent worked out the condition yet)
{
cout << " Enter Lower Range " << endl;
cin >> Lrange;
cout << " Enter Higher Range " << endl;
cin >> Hrange;
}
Anyone Know how I can enter the value from Lrange and Hrange into the array at like 0,1 and 1,1 and then increment the definedgroup by 1 each time. Thanks
Firstly, your code uses Variable Length Arrays which are a GCC extension. This means your code is not portable.
Now to read into the elements in the array, you could simply do:
Assuming that
iis an index into the array that you’ll get when you figure out the while loop condition.If you’d like to enlighten yourself, you could use a more idiomatic method: