Question

Using C++ please create a program for a first grader to practice subtractions. The program randomly...

Using C++ please create a program for a first grader to practice subtractions. The program randomly generates two single-digit integers number1 and number2. Ask the user to input the difference of the two numbers with always the greater number as the first operand. If the user inputs wrong answer, print a message, “Your answer is wrong. The correct answer is ” with the correct answer. Otherwise print “Your answer is correct.”

Hint:

1. Check if number1 < number2, otherwise swap them

2.Ask the user what is “number1 – number2”?

3.Print the message according to the user input

0 0
Add a comment Improve this question Transcribed image text
Answer #1
#include <iostream>
#include <cstdlib>
#include <ctime>

using namespace std;

int main(){
   int number1, number2;
   
   srand(time(0)); 

   number1 = rand()%10;
   number2 = rand()%10;
   
   if(number1 < number2){
      int t = number1;
      number1 = number2;
      number2 = t;
   }
   
   int res;
   cout<<"What is "<<number1<<" - "<<number2<<" ? ";
   cin>>res;
   
   if(number1-number2 == res){
      cout<<"Your answer is correct."<<endl;
   }
   else{
      cout<<"Your answer is wrong."<<endl;
   }
   
    return 0;
}

Add a comment
Know the answer?
Add Answer to:
Using C++ please create a program for a first grader to practice subtractions. The program randomly...
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
  • USING ANDROID STUDIO: Create an app that children can use to practice math skills. The math...

    USING ANDROID STUDIO: Create an app that children can use to practice math skills. The math skills that this app will support are: 2-digit additions 2-digit subtractions 1-digit multiplications 1-digit simple divisions where the remainder will always be zero The app will give the user a simple randomly generated math problem. If the user answers correctly, an encouraging message will be displayed, followed by options to select a new problem. If the answer is incorrect, the user will receive a...

  • Using C++ language P2-4 Write a program that randomly generates an integer and then prompts the...

    Using C++ language P2-4 Write a program that randomly generates an integer and then prompts the user to guess the number. If the user guesses the number correctly, the program outputs an appropriate message such as "You win!" and terminates. Otherwise, the program checks and tell the user whether the guessed number is less or greater than the target number and then prompts him for another try. However, the program gives the user five tries only to guess the correct...

  • Java language Part IV. Write programs (15 pts each) rite a program that generates a random...

    Java language Part IV. Write programs (15 pts each) rite a program that generates a random question of adding or subtracting two integers number and number2 under 20 (numbernumber2 in the case of subtraction) and prompt the user to enter the answer. After the user types the answer in the console, the program displays a message to indicate whether the answer is correct and gives the solution if the answer is wrong. Two sample runs are shown below. Tip: generat...

  • Write a JAVASCRIPT program that will help an elementary school student learn multiplication. Use the Random...

    Write a JAVASCRIPT program that will help an elementary school student learn multiplication. Use the Random method to produce two positive one-digit integers. The program should then prompt the user with a question using random numbers, such as How much is 6 times 7? The student then inputs the answer. Next, the program checks the student’s answer. If it is correct, display the message "Very good!" and ask whether the student wants to continue if so then ask another multiplication...

  • Original Question Problem: Game: learn addition) Write a program that generates two integers under 100 and prompts the...

    Original Question Problem: Game: learn addition) Write a program that generates two integers under 100 and prompts the user to enter the sum of these two integers. The program then reports true if the answer is correct, false otherwise. The program is similar to Listing 4.1. Modification needed to the prgraming code: The following modification nees to be added: the program presents random additions until the user enters -1, or the user answers incorrectly 2 questions in a row. *image...

  • PYTHON CODING Create a program that prompts the user twice. The first prompt should ask for...

    PYTHON CODING Create a program that prompts the user twice. The first prompt should ask for the user's most challenging course at Wilmington University. The second prompt should ask for the user's second most challenging course. The red boxes indicate the input from the user. Your program should respond with two copies of an enthusiastic comment about both courses. Be sure to include the input provided by the user to display the message. There are many ways to display a...

  • IN JAVA: Write a program that displays a menu as shown in the sample run. You...

    IN JAVA: Write a program that displays a menu as shown in the sample run. You can enter 1, 2, 3, or 4 for choosing an addition, subtraction, multiplication, or division test. After a test is finished, the menu is redisplayed. You may choose another test or enter 5 to exit the system. Each test generates two random single-digit numbers to form a question for addition, subtraction, multiplication, or division. For a subtraction such as number1 – number2, number1 is...

  • In c# create a program that generates a random number from 1 to 1000. Then, ask...

    In c# create a program that generates a random number from 1 to 1000. Then, ask the user to guess the random number. If the user's guess is too high, then the program should print "Too High, Try again". If the user's guess is too low, then the program should print "Too low, Try again". Use a loop to allow the user to keep entering guesses until they guess the random number correctly. Once they figure it, congratulate the user....

  • Java Programming Write a program that will help a student learn multiplication. Use SecureRandom object to...

    Java Programming Write a program that will help a student learn multiplication. Use SecureRandom object to produce two positive integers between 1 and 20. The program should then prompt the user with a question (use a sentinel-controlled loop), such as: How much is 10 times 11? The student then inputs the answer. If the answer is correct display the message “very good” and ask another question. If the answer is wrong to display the message “no, please try again” and...

  • Write a GUI-based Java application that implements the "Math Game" shown below. The program asks the...

    Write a GUI-based Java application that implements the "Math Game" shown below. The program asks the user to enter the answer of multiplying two one-digit random integers.  If the user enters a correct answer, a message will be displayed at the bottom of the frame, and the text field will be cleared.  If the user enters a wrong answer, a message will be displayed at the bottom of the frame asking for another answer.  If the user...

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