Question

Write the C++ language statements to ask a user to enter a number within the range...

Write the C++ language statements to ask a user to enter a number within the range of 0 to 100 (0 and 100 are valid inputs).

When the value is not valid, you should prompt the user to enter another value. (The user may enter many invalid numbers, so you must use loop). Only after the user enters a valid number should you display the message “Good” and the value of the number.

Homework Answers

Answer #1
#include <iostream>
using namespace std;

int main()
{
    int n;
    
    cout<<"Enter a number within the range of 0 to 100: ";
    cin>>n;
    
    while(n<0 || n>100){
        cout<<"Enter a number within the range of 0 to 100: ";
        cin>>n;
    }
    
    cout<<"Good "<<n<<endl;
    return 0;
}

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
Write a program in C++ coding that asks the user to input an integer between 25...
Write a program in C++ coding that asks the user to input an integer between 25 and 50, inclusive. Utilize a WHILE loop to test for INVALID input. If the input is INVALID, the loop will repeat, and ask the user to try again. The pseudocode looks like this: Prompt user to input an integer between 25 and 50 Accept the input from the user Test for invalid input (HINT: use a while loop and the OR operator with 2...
Write a program that asks the user to input an integer between 25 and 50, inclusive....
Write a program that asks the user to input an integer between 25 and 50, inclusive. Utilize a WHILE loop to test for INVALID input. If the input is INVALID, the loop will repeat, and ask the user to try again. The pseudocode looks like this: Prompt user to input an integer between 25 and 50 Accept the input from the user Test for invalid input (HINT: use a while loop and the OR operator with 2 relational expressions. You...
Write a while loop to ask the user to type number of hours(double) they work per...
Write a while loop to ask the user to type number of hours(double) they work per day. Calculate and print the salary for each valid input. If number of hours is greater than or equal to 0 and less than 5, then:  salary = numberofhours * 5, loop continues, the user can type another number If number of hours is greater or equal to 5, and less than 10, then: salary = numberofours * 8, loop continues, the user can type...
Write a mips assembly language program that asks the user to enter and integer number and...
Write a mips assembly language program that asks the user to enter and integer number and read it. Then ask him to enter a bit position (between 0 and 31) and display the value of that bit.
Write a powershell script which will ask the user to enter a number. If the answer...
Write a powershell script which will ask the user to enter a number. If the answer is not equal to 10 display message "Congratulations".
8.39 Lab 8d: Even Entry Loop This program will ask the user to enter an even...
8.39 Lab 8d: Even Entry Loop This program will ask the user to enter an even number and continue to do so until they enter the given QUIT condition. The prompt for the user to enter a number is written as follows: "Enter an even number or [QUIT] to quit:" The quitting condition in this case will be the number 999. If the number they entered was an even number, output the message "Good job!" Otherwise, output the message "[number]...
Write a program that prompts the user to enter an integer number between 1 and 999....
Write a program that prompts the user to enter an integer number between 1 and 999. The program displays the sum of all digits in the integer if the input is valid; otherwise, it displays a message indicating that the integer is not between 1 and 999 and hence, is invalid. Name the program file Q1.cpp Example: if the user enters 12, sum of digits is 3. If the user enters 122, sum of digits is 5.
Please use Python 3 4). Write a program that asks the user to enter 10 numbers....
Please use Python 3 4). Write a program that asks the user to enter 10 numbers. The program should store the numbers in a list and then display the following data: • The lowest number in the list • The highest number in the list •The total of the numbers in the list • The average of the numbers in the list   Sample input & output: (Prompt) Enter Number 1: (User enter) 4 (Prompt) Enter Number 2: (User enter) 7...
Write a C program to ask the user 3 number and display in the greater value...
Write a C program to ask the user 3 number and display in the greater value from it. Only use compound condition in if-Else statements.
design a program that prompts the user to enter a positive integer number and reads the...
design a program that prompts the user to enter a positive integer number and reads the user’s input. If the user input is not a positive number, the program should prompt them repeatedly until they enter a valid input. Once a valid input is received ,the program uses a loop to calculate the sum of the digits of the user’s input and displays the sum. For example, if the user enters the number 94311, the program should print the sum...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT
Active Questions
  • Determine the effects of the following on a cash basis taxpayer’s gross income for 2018 and...
    asked 7 minutes ago
  • XYZ is a calendar-year corporation that began business on January 1, 2017. For 2018, it reported...
    asked 35 minutes ago
  • Although aging and death are realities that all individuals have to deal with at some point...
    asked 59 minutes ago
  • Implement the following functions with AVR assembly language 1) 2-byte addition (i.e, addition on 16-bit numbers)...
    asked 1 hour ago
  • Assume you have a chemical compound (HA) that is a weak acid which changes color upon...
    asked 1 hour ago
  • A company has two divisions. The first division consists of project management and generated $4,523,367 of...
    asked 1 hour ago
  • Practice Quiz 1 Use the following information to answer questions 1 through 5.                              &
    asked 1 hour ago
  • 3) The corrosion of iron is an electrochemical process that involves the standard reduction potentials given...
    asked 2 hours ago
  • Type or paste question here In 2015, the United States is still recovering from the recession....
    asked 2 hours ago
  • Failures of a critical machine part due to cyclical vibration has a gamma distribution with a...
    asked 2 hours ago
  • f(x)=ln(1+2x), a=4,n=3,3.7<=x<=4.3 (b) Use Taylor's Inequality to estimate the accuracy of the approximation f  Tn(x) when x...
    asked 2 hours ago
  • What is the meaning of convergent and divergent series? Explain your answer with example.
    asked 2 hours ago