int x=0;
while(x<6)
{
int a;format output.
int m = Hrand();value in int m.
Balls[x] = m; because of an error.
a = Balls[x];
cout<<"["<<setfill('0')<<setw(02)<<a<<"]";
x++;
}
Here, I also fixed a bug. Since Balls has 6 elements, the last element will be 5. Thus you want x<6
instead of x<=6
. That goes for the for loop too.
One drawback of while loops is that you cannot declare local variables with them.
0
solved how to convert an for loop to while loop c++