0

#include <iostream using namespace std; int main(a= 2); { while(a <=100) cout<<"this is even"<< a << ln; }

what is wrong in that code

28th Jan 2017, 5:33 AM
Scooby Doo
Scooby Doo - avatar
9 Respostas
+ 4
So start with a value of 0 in a. int a = 0;
28th Jan 2017, 6:50 AM
Jafca
Jafca - avatar
+ 3
A lot, it should be: #include <iostream> using namespace std; int main() { int a = 2; while(a <= 100) { cout << a << " is even" << endl; a += 2; } return 0; }
28th Jan 2017, 6:13 AM
Jafca
Jafca - avatar
+ 2
Was it meant to be an infinite loop?
28th Jan 2017, 6:45 AM
Jafca
Jafca - avatar
+ 2
I thought you wanted to print out all the evens from 2 to 100. a += 2 is the same as a = a + 2 So the value of a increases by two every loop.
28th Jan 2017, 6:47 AM
Jafca
Jafca - avatar
+ 1
thanks
28th Jan 2017, 6:35 AM
Scooby Doo
Scooby Doo - avatar
0
it is an infinite loop
28th Jan 2017, 6:44 AM
Scooby Doo
Scooby Doo - avatar
0
what is the use of a+=2; statements
28th Jan 2017, 6:45 AM
Scooby Doo
Scooby Doo - avatar
0
no I needed to find the evens btwn 0 to 100
28th Jan 2017, 6:48 AM
Scooby Doo
Scooby Doo - avatar