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; }
10 odpowiedzi
+ 1
and you added the “greater then” ( for lack of better term) symbol before endl
+ 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
+ 2
but the code recognizes indentations or i dont have to?
+ 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;
+ 1
Should be:
int a=1;
while (a<5) {
cout << "a is less then 5" << endl;
a++;
}
+ 1
only one set of brackets?
+ 1
why cant it just be
cout << “1+1=2”; ?
+ 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;
+ 1
oh so that was sort of if like ‘2’ was the int i set at the begining?
+ 1
Yes.