The program reads integers from input using a while loop. Write an expression that executes the while loop until an integer read from input is less than or equal to 0.
Ex: If input is 15 23 -14, then the output is:
Integer is 15
Integer is 23
Exit
CHALLENGE ACTIVITY
4.2.2: While loops.
401138.2627134.qx3zqy7
0 1
Jump to level 1
The program reads integers from input using a while loop. Write an expression that executes the while loop until an integer read from input is less than or equal to 0.
Ex: If input is 1523-14, then the output is:
3
Integer is 15
Integer is 23
Exit
#include <iostream>
using namespace std;
int main() {
int input;
cin >> input;
while (input > 0) {
cout << "Integer is " << input << endl;
cin >> input;
}
cout << "Exit" << endl;
}
Check
Next level