Questions


Related Questions:


Questions

Asked By :  Brianna Anderson
Answers1

A while loop reads integers from input write an expression

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 172642, then the output is: Integer is 17 Integer is 26 Loop terminated 1 #include 2 using namespace std; 4 int main() \{ 5 int in; 6 in  in; 97. while ( inet-16) 18 cout « "Integer is " « in «end; 11 cin  in; 12 3 13 cout  "Loop terminated"  endl; 15 2 3 The whise loop iterates and outputs "integer is", followed by the integer read from input, until a positive integer is read from input. Then, the loop terminates and "Loop terminated" is output Not ath tests passed




Answers :

0

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;
}

Explanation:

  • The program uses cin to read integers from input.
  • The while loop condition in <= 0 ensures that the loop continues as long as in is non-positive (either zero or negative).
  • Inside the loop, it prints the current integer with the message "Integer is" and then reads another integer.
  • When a positive integer is read, the condition in <= 0 becomes false, and the loop exits.
  • Finally, it prints "Loop terminated".

Feel free to ask further questions if needed!


Answered By

Craig Gilmore

Your Answer



XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
Write your answer, be as detailed as possible...

Reply as a guest

Required but never shown

Try Now AI powered Content Automation