1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
gregori [183]
3 years ago
7

Create a program that displays a menu to select addition, subtraction, or multiplication. Using random numbers between 0 and 12

(including 0 and 12), present a math problem of the type selected to the user. Display a "correct" or "incorrect" message after the user enters their answer. In C++
Computers and Technology
1 answer:
Lemur [1.5K]3 years ago
6 0

Answer:

This question is answered using C++

#include<iostream>

#include <cstdlib>

#include <ctime>

using namespace std;

int main(){

   int ope, yourresult;

   cout<<"Select Operator: \n"<<"1 for addition\n"<<"2 for subtraction\n"<<"3 for multiplication\n";

   cout<<"Operator: ";

   cin>>ope;

   srand((unsigned) time(0));

   int num1 = rand() % 12;

   int num2 = rand() % 12;

   int result = 1;

   if(ope == 1){

       cout<<num1<<" + "<<num2<<" = ";

       result = num1 + num2;

   }

   else if(ope == 2){

       cout<<num1<<" - "<<num2<<" = ";

       result = num1 - num2;

   }

   else if(ope == 3){

       cout<<num1<<" * "<<num2<<" = ";

       result = num1 * num2;

   }

   else{

       cout<<"Invalid Operator";

   }

   cin>>yourresult;

   if(yourresult == result){

       cout<<"Correct!";

   }

   else{

       cout<<"Incorrect!";

   }

   return 0;

}

Explanation:

This line declares operator (ope) and user result (yourresult) as integer

   int ope, yourresult;

This prints the menu

   cout<<"Select Operator: \n"<<"1 for addition\n"<<"2 for subtraction\n"<<"3 for multiplication\n";

This prompts the user for operator

   cout<<"Operator: ";

This gets user input for operator

   cin>>ope;

This lets the program generates different random numbers

   srand((unsigned) time(0));

This generates the first random number

   int num1 = rand() % 12;

This generates the second random number

   int num2 = rand() % 12;

This initializes result to 1

   int result = 1;

If the operator selected is 1 (i.e. addition), this prints an addition operation and calculates the actual result

<em>    if(ope == 1){</em>

<em>        cout<<num1<<" + "<<num2<<" = ";</em>

<em>        result = num1 + num2;</em>

<em>    }</em>

If the operator selected is 2 (i.e. subtraction), this prints an subtracttion operation and calculates the actual result

<em>    else if(ope == 2){</em>

<em>        cout<<num1<<" - "<<num2<<" = ";</em>

<em>        result = num1 - num2;</em>

<em>    }</em>

If the operator selected is 3 (i.e. multiplication), this prints an multiplication operation and calculates the actual result

<em>    else if(ope == 3){</em>

<em>        cout<<num1<<" * "<<num2<<" = ";</em>

<em>        result = num1 * num2;</em>

<em>    }</em>

If selected operator is not 1, 2 or 3, the program prints an invalid operator selector

<em>    else{</em>

<em>        cout<<"Invalid Operator";</em>

<em>    }</em>

This gets user input

   cin>>yourresult;

This checks if user result is correct and prints "Correct!"

   if(yourresult == result){

       cout<<"Correct!";

   }

If otherwise, the program prints "Incorrect!"

<em>    else{</em>

<em>        cout<<"Incorrect!";</em>

<em>    }</em>

   return 0;

You might be interested in
Firestick optimizing system storage and applications loop
fiasKO [112]

Answer:

IF THIS DOES OCCUR THEN THE SYSTEM WILL AUTOMATICALLY CUT OFF WITH NO WARNING AT ALL...

Explanation:

ON WHAT INFORMATION AND RESEARCH HAS GIVEN ME IT WILL BE THE  AWNSER GIVEN AT THE TOP...

7 0
2 years ago
If a fire should break out in your building, which of the following actions is NOT recommended?
quester [9]

C) Scream and run

you need to remain calm and carefully exit the building making sure you have everybody with you

6 0
3 years ago
Read 2 more answers
Which university first developed the use of email?
Arte-miy333 [17]

Answer:

Massachusetts Institute of Technology (MIT)

Explanation:

4 0
2 years ago
Will sum1 come bust me outta FCA....replies u gotta live in knoxville though
snow_tiger [21]

Answer:

im on my way cuz

Explanation:

4 0
2 years ago
Read 2 more answers
Which html tag designates links to other web pages?.
Tcecarenko [31]

Answer:

<a href>

Explanation:

I found the answer on a Quizlet.

I hope this helps!

3 0
2 years ago
Other questions:
  • Write a converter program for temperatures. This program should prompt the user for a temperature in Celsius. It should then con
    10·1 answer
  • With a(n) ____ data table you can vary the value in one cell.
    5·1 answer
  • What are the three main purposes of an operating system? Explain how the old mainframe computers were different from the compute
    12·1 answer
  • A slightly tapered thread is characteristic of a _______ tap.
    15·1 answer
  • Which option can Jesse use to customize her company’s logo, name, address, and similar details in all her business documents?
    7·1 answer
  • Write a function to output an array of ints on a single line. Funtion Should take an array and an array length and return a void
    9·1 answer
  • Match the installation type to its description.
    9·1 answer
  • Which of the following correctly declares and initializes a Scanner object that will use input from the keyboard as its data sou
    13·2 answers
  • A computer is performing a binary search on the sorted list of 7 numbers below. What is the maximum number of iterations needed
    15·1 answer
  • If Anime Characters were real , Who Would Your Anime Wife Would Be (Tell Who And Why)
    10·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!