0
How can I add more variables to a for loop in C++?
I tried to add more variables to a for loop by this: for(int a = 10, b = 11; a != 0; a--, b++) { ... } When i try to run it my compiler says, 'error: unqualified-id before 'int' '
5 Answers
+ 8
I just copied your text and it worked just fine, I think the error is somewhere else:
https://code.sololearn.com/cis8zLKFwwG3/?ref=app
+ 6
computer says no
+ 6
It works fine for me.
#include <iostream>
using namespace std;
int main() {
for (int a = 0, b = 3; a < b; a++, b--) {
cout << a;
}
return 0;
}
It says 01 as I expected..
+ 6
I don't have a desktop at the moment, but I do remember encountering the same errors when trying to declare more than one variable in a for loop. Code Playground, however, does not reflect this error. I will check on this when I have time.
+ 4
I found my error and i made a error in the question. Sorry.
I don't write the code that i wrote in the question. I write two times int for(int a=10, int b=11...
Now it works for me fine
Thank you all for your ideas