224k views
0 votes
Write a do-while loop that continues to prompt a user to enter a number less than 100, until the entered number is actually less than 100. End each prompt with a newline. Ex: For the user input 123, 395, 25, the expected output is:

Enter a number (<100):
Enter a number (<100):
Enter a number (<100):
Your number < 100 is: 25
c++

#include
using namespace std;
int main() { int userInput = 0;

do
cout << "Your number < 100 is: " << userInput << endl;

return 0;
}

1 Answer

1 vote

Answer:

The following do while loop is given below

do

{

cout << "Enter a number (<100): "; // print the message

cin >> userInput; // Read the number by user

}while(userInput>100); // checking the condition

Explanation:

Following are the description of above statement

  • In the above do-while loop print the message "Enter a number (<100): " by using the cout function .The cout function in C++ is used to display the number or message in the console window.
  • Read the Number by user in "userInput" variable by using cin function.
  • Finally check the condition by greater than 100.This loop will continue if the user reads the number greater then 100.If the user enters the number less then 100 the execution of the loop will stop.

User Wouter Simons
by
3.8k points