A while loop reads integers from input. Write an expression that executes the while loop until a positive integer is read from input. Ex: If the input is −17−2642, then the output is: Integer is −17 Integer is −26 Loop terminated 1 #include
It looks like you're describing a C++ program that reads integers from input and continues to do so until a positive integer is encountered. Below is a corrected version of your program code with proper syntax and formatting:
#include <iostream>
using namespace std;
int main() {
int in;
cin >> in;
// Continue looping until a positive integer is read
while (in <= 0) {
cout << "Integer is " << in << endl;
cin >> in;
}
cout << "Loop terminated" << endl;
return 0;
}
cin
to read integers from input.while
loop condition in <= 0
ensures that the loop continues as long as in
is non-positive (either zero or negative).in <= 0
becomes false, and the loop exits.Feel free to ask further questions if needed!
Answered By