I have this c++ code for my uni project…
for (int a=0; a<definedgroups; a++)
{
cout << "Enter Lower number for group " << a << ": ";
cin >> User_Groups [a] [0] ;
}
Now I want to declare another loop that displays the number
could I use A from the first variable and say…
while (a>0)
{
displays code, have written yet
}
or is that “a” only recognised in that first for loop.
Thanks
variable
ascope is only withing thefor loop.If you want to access
ain thewhile loop, you need to assign it to a global variable outside of both the loops.Assuming you want to access each different values of
a, then you need to store it in an array, which then doesnt really make any sense since you can just create an increasing order ofints.But if that is what you want to do then here is what I would do, since piokuc already answered.