Question

C++ Write a program that prompts the user to enter two positive integers: num1 and num2....

C++

Write a program that prompts the user to enter two positive integers: num1 and num2.

- Validate that num1 is less than num2 and that both numbers are positive. If any of these conditions are not met, allow the user to re-enter num1 and num2 until the input is determined valid.

- For all integers from num1 through num2, print the word keyboard if the current integer is divisible by 2 and print the word mouse if the current integer is divisible by 3.

-If a number is divisible by both 2 and 3, the words keyboard mouse are printed.

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

int main () {
   int num1, num2;
   cout<<"Enter two positive integers: ";
   cin>>num1;
   cin>>num2;
   while(!((num1<num2) && num1>0 && num2>0)){
      cout<<"Enter two positive integers: ";
      cin>>num1;
      cin>>num2; 
   }
   for(int i = num1;i<=num2;i++){
      if(i%2==0 && i%3==0){
         cout<<"keyboard mouse"<<endl;
      }
      else if(i%2==0){
         cout<<"keyboard"<<endl;
      }
      else if(i%3==0){
         cout<<"mouse"<<endl;
      }
   }
   return 0;
}

Add a comment
Know the answer?
Add Answer to:
C++ Write a program that prompts the user to enter two positive integers: num1 and num2....
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
  • C++ Write a program that prompts the user to enter integers or a sentinel to stop....

    C++ Write a program that prompts the user to enter integers or a sentinel to stop. The program prints the highest and lowest numbers entered, the sum and the average. DO NOT USE ARRAYS, only variables and loops. Write a program the prompts the user to input a positive integer. Keep asking the user until a positive integer is entered. Once a positive integer is entered, print a message if the integer is prime or not. (NOTE: A number is...

  • Write a program that prompts the user for positive integers, only stopping when a negative integer...

    Write a program that prompts the user for positive integers, only stopping when a negative integer or zero is given. The program should then print out how many of the positive integers were odd. Example: Enter a positive integer (0 or negative to stop): 9 Enter a positive integer (0 or negative to stop): 4 Enter a positive integer (0 or negative to stop): 7 Enter a positive integer (0 or negative to stop): -3 You entered 2 odd integers....

  • 1. Write a program that prompts the user to enter three integers and display the integers...

    1. Write a program that prompts the user to enter three integers and display the integers in non-decreasing order. You can assume that all numbers are valid. For example: Input Result 140 -5 10 Enter a number: Enter a number: Enter a number: -5, 10, 140 import java.util.Scanner; public class Lab01 { public static void main(String[] args) { Scanner input = new Scanner(System.in);    } } ---------------------------------------------------------------------------------------------------------------------------- 2. Write a program that repeatedly prompts the user for integer values from...

  • 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...

  • Summary: Write a C program that prompts the user to enter 2 positive integer numbers, display...

    Summary: Write a C program that prompts the user to enter 2 positive integer numbers, display the numbers in 3 formats. Then check, whether the larger of the 2 is evenly divisible by the smaller. Detail: Write a complete C program, more complex than the typical "hello world" program. Prompt the user to enter 2 integer numbers that are not negative. After either entry, display that number again. Print the smaller in hexadecimal, in decimal, and in octal format. Include...

  • Write a program that prompts the user to enter an integer and checks whether the number...

    Write a program that prompts the user to enter an integer and checks whether the number is divisible by both 5 and 6, divisible by 5 or 6, or just one of them (but not both). SAMPLE OUTPUT Enter an integer: 10 Is 10 divisible by 5 and 6? False Is 10 divisible by 5 or 6? True Is 10 divisible by 5 or 6, but not both? True (Python programming language)

  • Write java program that prompts the user to enter integers from the keyboard one at a...

    Write java program that prompts the user to enter integers from the keyboard one at a time. Program stops reading integers once the user enters the same value three times consecutively. Program then outputs "Same entered 3 in a row. "

  • MULIMI Umplicated than the hrst assignment. Write a program that will let the user enter an...

    MULIMI Umplicated than the hrst assignment. Write a program that will let the user enter an integer. If the integer is less than 5 make the actual input value be 50. We will call the value that the user put in N. Print the integers from 1 to None number on each line. If the number you are going to print is divisible by 3 print the word fuzz instead of the number. If the number is divisible by 5...

  • In C++, Write a program that it prompts to user for two integers, computes the quotient...

    In C++, Write a program that it prompts to user for two integers, computes the quotient of two integers, and then displays the result. You need to do the following things in this assignment: + The main function prompts for user input and reads the two integers that the user entered. + Write a quotient function that computes the quotient of two integers and return the results. (hint: avoid integer division and divide by zero)

  • Write a perl program that prompts a user for a number and checks that number against...

    Write a perl program that prompts a user for a number and checks that number against three possibilities. If the number is divisible by 3, it should print fizz, if its divisible by 5 it should print buzz, and if its divisible by 3 and 5 it should print fizzbuzz. It should do nothing if none of those conditions are met. I need help with this.

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