Question

3. Compose code that prompts the user to enter a number in the range of 1 through 100 and validates the input. [In C++ Please

0 0
Add a comment Improve this question Transcribed image text
Answer #1
#include <iostream>
using namespace std;

int main(){
   int n;
    cout<<"Enter number: ";
    cin>>n;
   
   while(n<1 || n>100){
       cout<<"Invalid number\n";
       cout<<"Enter number: ";
        cin>>n;
   }
   
   cout<<"Valid number: "<<n<<endl;
   return 0;
}

Output:

Enter number: -1 Invalid number Enter number: 200 Invalid number Enter number: 101 Invalid number Enter number: 45 valid numb

Add a comment
Know the answer?
Add Answer to:
3. Compose code that prompts the user to enter a number in the range of 1...
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. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Design a Python program that prompts the user to enter "yes" or "no" and validates the...

    Design a Python program that prompts the user to enter "yes" or "no" and validates the input. (Use a case-insensitive comparison) and another Python program that prompts the user to enter a number in the range of 1 through 100 and validates the input

  • Question 16 Write code that prompts the user to enter a positive nonzero number and validates...

    Question 16 Write code that prompts the user to enter a positive nonzero number and validates the input:

  • Write a code segment that prompts the user to enter a double number between (5.55 and...

    Write a code segment that prompts the user to enter a double number between (5.55 and 123.3) inclusive. If the input is invalid, print an error message and loop until the input is valid. Code in c++

  • write in C++ Exercise#1: Is it a Prime? Write a program that prompts the user to...

    write in C++ Exercise#1: Is it a Prime? Write a program that prompts the user to enter a positive integer in the range [100, 100000]. If the integer is not in the specified range the program prompts the user again. The program prints whether the integer is a prime number or not. Sample input/output nter an integer in the range [10e, 10eeee]: 39 nter an integer in the range [100, 100000]: 120453 Enter an integer in the range [10e, 10e000e]:...

  • Write a program that prompts the user to enter a number within the range of 1...

    Write a program that prompts the user to enter a number within the range of 1 to 10 inclusive. The program then generates a random number using the random class: If the users guess is out of range use a validation loop (DO) to repeat the prompt for a valid number, If the users guess matches the random number tell them they win! If the users guess does not match the random number tell them they are wrong. Use a...

  • c++ • Prompts the user to enter floating point numbers that represent daily sale amounts at...

    c++ • Prompts the user to enter floating point numbers that represent daily sale amounts at a store o Allows the user to indicate the end of user inputs with -1 o Validates the user input for numbers greater than 0 o Stores the numbers in an array • Determines and displays the maximum, minimum, and arithmetic mean (average) of the sale amounts

  • Python Code Write a program using functions and mainline logic which prompts the user to enter...

    Python Code Write a program using functions and mainline logic which prompts the user to enter a number. The number must be at least 5 and at most 20. (In other words, between 5 and 20, inclusive.) The program then generates that number of random integers and stores them in a list. The random integers should range from 0 to 100. (You can use a wider range if you want, but the lower end of the range must be at...

  • Java: Write a program that prompts the user to enter integers in the range 1 to...

    Java: Write a program that prompts the user to enter integers in the range 1 to 50 and counts the occurrences of each integer. The program should also prompt the user for the number of integers that will be entered. As an example, if the user enters 10 integers (10, 20, 10, 30, 40, 49, 20, 10, 25, 10), the program output would be: 10 occurs 4 times 20 occurs 2 times 25 occurs 1 time 30 occurs 1 time...

  • Use a C++ program to run your code that prompts the user to enter an integer,...

    Use a C++ program to run your code that prompts the user to enter an integer, greater or equal to 2, and displays its largest factor other than itself. To answer for this question, It is required that you use following two functions to complete the assignment. a.     // Prompts the user to enter an integer: number >=2         void getNumber( int& number); b.     // returns the largest factor of n other than itself         int getLargestNonSelfFactor(int n);

  • C++ only Implement a program that prompts a user to enter a number N where N...

    C++ only Implement a program that prompts a user to enter a number N where N is a positive number. The program must validate a user input and ask a user to re-enter until an input is valid. Implement a function that pass N as an argument and return a result of calculates N! (N-factorial): The function must use loop for the implementation. Hint: Factorial: N! = N * (N-1) * (N-2) * …. * 1 ( This is only...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT