14.5k views
4 votes
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 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

2 Answers

4 votes

Final answer:

The student seeks to understand how to create a do-while loop that continues to prompt for a number until one less than 100 is entered. This is achieved using a loop that checks the value after input and repeats if the condition is not met, ending with the prompt and printing the valid number.

Step-by-step explanation:

The question asks how to write a do-while loop that repeatedly prompts the user to enter a number until they input a number that is less than 100. Here's how one might write this loop in a programming language such as C++:

int number;
do {
std::cout << "Enter a number (<100):\\";
std::cin >> number;
} while (number >= 100);
std::cout << "Your number < 100 is: " << number << std::endl;

This loop uses the do-while structure to keep asking for a number. The condition at the end of the 'do' block checks if the entered number is 100 or greater. If it is, the loop repeats. If not, the loop ends and prints the number that is less than 100.

User Atams
by
5.3k points
4 votes

Answer:

Step-by-step explanation:

import java.util.Scanner;

//Declare the class NumberPrompt.

public class NumberPrompt

{

public static void main(String args[])

{

/*Declare the variable of scanner class and allocate the

memory.*/

Scanner scnr = new Scanner(System.in);

//Initialize the variable userInput.

int userInput = 0;

/* Your solution goes here*/

//Start the do-while loop

do

{

//Prompt the user to enter the number.

System.out.println("Enter a number(<100)");

/*Store the number entered by the user in the

variable userInput.*/

userInput=scnr.nextInt();

}while(userInput>=100);/*Run the do-while loop till the

user input is greater than 100*/

//Print the number which is less than 100.

System.out.println("Your number <100 is "+userInput);

return;

}

}

Output:-

a do-while loop that continues to prompt a user to enter a number less than 100, until-example-1
User Gpcola
by
5.4k points