119k views
4 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: 25c++ #include using namespace std;int main() { int userInput = 0;do cout << "Your number < 100 is: " << userInput << endl; return 0;}

User Hrickards
by
7.6k points

1 Answer

7 votes

Answer:

#include<iostream>//library inclusion

using namespace std;

int main()

{

int userInput;

do//start of do while loop

{

cout << "Enter a number less than a 100" << endl;

cin >> userInput;

if (userInput < 100) //condition

{

cout << "YOu entered less than a hundred: " << userInput << endl;

}

else

{

cout << "your number is greater than 100" << endl;

}

} while (userInput > 100);//condition for do while

return 0;//termination of int main

}

Step-by-step explanation:

The program has been commented for you. The do-while loop enters the first loop regardless of the condition. Then after the first iteration, it checks for the condition. If the condition is being met, it will iterate through, again. Otherwise it will break out of the loop and land on the "return 0;" line. Which also happens to be the termination of the program in this case. The if-else condition is used for the user to see when prompted.

User RobC
by
7.8k points