I need a program with a nested for loop. It asks the user for n, a postive value, if it is negative it exits the program. once n is entered positively it must make an nxn checkerboard pattern made from x and o.
example: positive in 4
XOXO
OXOX
XOXO
OXOX
int n;
cout << "enter positive value:";
cin >> n;
for (int n = 1; n < n++; n++){
for (int n = 0; n < 0; n++){
break;
}
cout << "XOXO" << endl;
}
i tried this but it wont compile it says
expected initializer befor %
I think there may be something you aren't showing us, but one glaring problem is that you re-define n inside the outer loop, then inside the inner loop. By convention, use:
1 2 3 4
for (int i = 0; i != something; i++)
{
for (int j =0; j != somethingElse; j++) {}
}