0

What’s wrong with this please?

#include <iostream> using namespace std; int main() { int a=1; { while (a<5); cout << "a is less then 5"; endl } a++; return 0; }

19th Feb 2019, 5:08 AM
Eli
10 odpowiedzi
+ 1
and you added the “greater then” ( for lack of better term) symbol before endl
19th Feb 2019, 5:17 AM
Eli
+ 2
The whole code would be this: #include <iostream> using namespace std; int main() { int a=1; while (a<5) { cout << "a is less then 5" << endl; a++; } return 0; } You probably noticed that I indented some lines; that is because it shows which lines are in functions and loops
19th Feb 2019, 5:15 AM
Rowsej
Rowsej - avatar
+ 2
but the code recognizes indentations or i dont have to?
19th Feb 2019, 5:16 AM
Eli
+ 2
You don’t have to to indentations, ut it is a good practice to. And how cout works is you seperate things you want to print by <<s. For example, to print 1 + 1 = 2 would be: cout << "1 + 1 = " << 2;
19th Feb 2019, 5:30 AM
Rowsej
Rowsej - avatar
+ 1
Should be: int a=1; while (a<5) { cout << "a is less then 5" << endl; a++; }
19th Feb 2019, 5:11 AM
Rowsej
Rowsej - avatar
+ 1
only one set of brackets?
19th Feb 2019, 5:12 AM
Eli
+ 1
why cant it just be cout << “1+1=2”; ?
19th Feb 2019, 5:33 AM
Eli
+ 1
It can be like that, just I’m showing you how to print multiple things at once instead of: cout << a; cout << b; Where it can be: cout << a << b;
19th Feb 2019, 5:34 AM
Rowsej
Rowsej - avatar
+ 1
oh so that was sort of if like ‘2’ was the int i set at the begining?
19th Feb 2019, 5:35 AM
Eli
+ 1
Yes.
19th Feb 2019, 5:36 AM
Rowsej
Rowsej - avatar