0
why does it always printone number
int num=1; while(num>6){ cout<<num<<endl; num=num++; } why it doesnt print 12345?
3 Réponses
+ 3
also your condition is false. change it to num<6
+ 2
It actually doesn't print anything, right?
The first line says that num is 1, and the second asks if 1 is bigger then 6 which is false. Though it never enters in your while loop.
The correct would be:
int num=1;
while (num < 6){
cout << num << endl;
num++;
}
+ 2
if you want increase your counter, in this case num, you can use one of this statements:
num++;
++num;
num = num + 1;
num = ++num;
apparently your way of increasing num is known as "undefined behaviour" and it is a complicated issue to understand by new programmers such me.
so dont use this:
num = num++;