@ pured18 the variable i is still in scope when nested inside the j loop, i is not being assigned outside of the closing }where it was first declared, so it use still usable.
#include <iostream>
usingnamespace std;
int main ()
{
int num;
cout << "How far do you want this program to count minus one?\n";
cin >> num;
cout << endl;
for (int i = 0; i < num; i++) {
for (int j = 0; j < i; j++ ) {
cout << ".";
}
cout << i << endl;
}
return 0;
}
Btw, cout << i; is wrong in your example because you are in the j loop, which will make it output 1, j times before it changes the value of i to 2.
novellof wrote:
@ pured18 the variable i is still in scope when nested inside the j loop, i is not being assigned outside of the closing }where it was first declared, so it use still usable.
@jasonwynn10cout << "How far do you want this program to count minus one?\n"; ugh..why would you have the user do basic math you could do in the program :P That doesn't really make sense since you are doing [0,num) so it should iterate num times.
The best way I think would be what Pured mentioned and use setw and setfill