+ 4
Why cout<<x+1 is not giving answer??
code of solo - https://www.sololearn.com/learn/CPlusPlus/1614/ code of my - https://code.sololearn.com/cUrAQ428uefy/?ref=app
7 Respostas
+ 3
You don't get any output here, as your loop is an infinite one. The 'x' remains to be 5 and never becomes 6. So you need to assign it thr new value if you want the loop to end.
Use the preincrement operation:
#include <iostream>
using namespace std;
int main()
{int x=5;
while(x<9)
cout<<++x;
return 0;
}
+ 3
thanks..for helping 😍😍
+ 2
@procpp i have mentioned my written code
+ 2
It's because you are not increasing the value of x in the bucle, you join in a infinite loop.
Write:
cout << x++;
and it will work.
Another way is to do (inside the while bucle):
cout << x;
x += 1; // (or x++;)
+ 2
@Misa Amane
You may, but without the x++, ++x or x+=1, the loop executes forever.
+ 1
Umm, where exactly? Can you share the code? Maybe you missed the 'int x' part?
0
If x is not a function,cout<<x+1 will output only "x+1"