0
Using a while loop
would anyone tell me why this code gives no output please ? #include <iostream> using namespace std; int main() { int num = 1; int number; while (num <= 5) { cin >> number; num++; } return 0; }
1 Answer
+ 7
All the while loop is doing is receiving a value for number. Nothing is being done with it. Tack on a cout inside the loop or at the end of the code.
Also, you're getting an input for number 5 times, and the newest one overwrites the last one. Only the last input will actually be stored.