Hey guys, this is a recurring problem I've had whenever I try to use the while loop. It says it expects a ';' before a parenthesis but it doesn't need one. I'll post the code it's happening in below.
1 2 3 4 5 6 7 8 9 10
int main()
{
int X = 10;
while(X; X <= 0; X--)
cout << X << endl;
return 0;
}
The exact error is:
"Error: expected ')' before ';' token"
and
"Error: expected ';' before ')' token"
on line 11 (line 5 here).
Any help would be appreciated. And I've also got a question regarding some math I need help with but have yet to write in the code.
int X = 10;
while(X != 0) // <== This is how a while loop works.
{
cout << X << endl;
X--;
}
for(X; X >= 0; X--) // <== You are trying to do this! ( Just change your while to for )
cout << X << endl;