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
William found out that someone used his report on American culture without his permission. What is William a victim of?
Mnenie [13.5K]

He is a victim of plagiarism.

Plagiarism is when someone steals someone else's work, to help benefit themselves. Taking credit for the other person work.

Hope this helps!

3 0
3 years ago
Read 2 more answers
What are the three primary separation of concerns on the client-side of a dynamic web application? (Check all that apply)
nlexa [21]

Answer:

Behaviour

Style

Structure

Explanation:

Above are the three primary separation of concerns for a web application at client side.

Structure --> we can define the structure of the application at client side using HTML

style-->style is used to give some styling information like font,color,headings so on at client side .In general we use CSS to do this at client side

Behaviour--> it actually defines the functionality of the elements at client side like when we click button what it should do.We will use JavaScript to define the behaviours at client side

7 0
3 years ago
What is the main idea of this article? Please someone help me. I will give brainliest answer
mart [117]
The main idea of this article is that theme parks are conducting scientific research that is benefiting the community. Hope this helps!
8 0
3 years ago
whenever I try to make an account it says it can't sign me up at this time or something- can you help?-
Rus_ich [418]

Answer:

You can try emailing tech support and describing your issue. In order to get the best help as quickly as possible, try providing screenshots of what happens when you sign in or describe everything you see on the screen when the problem occurs, and quote error messages directly when possible.

5 0
2 years ago
At what depth does an employer need to use a protection system to ensure the safety of workers in a trench or excavation?
nevsk [136]
Trench 4 foot or deeper and must be located 25 foot within eachother
3 0
3 years ago
Read 2 more answers
Other questions:
  • Given 3 floating-point numbers. Use a string formatting expression with conversion specifiers to output their average and their
    14·1 answer
  • ________ work(s) by using radio waves to communicate with radio antennas placed within adjacent geographic areas.
    8·1 answer
  • A variation of pronounce is a. Proclaim c. Produce b. Profound d. Pronunciation Please select the best answer from the choices p
    11·1 answer
  • Advantages and disadvantages of technology
    13·1 answer
  • i need to also do a algorithm where if the total is a even number 10 points are added to the score and if the total is odd then
    11·1 answer
  • Lucy has to move data from column A to column N in a worksheet. Which keys should she select to move data in the same worksheet?
    9·2 answers
  • What are Manuscript signs​
    8·1 answer
  • What are the origins of the parking barrier?
    12·1 answer
  • Define artificial intelligence?​
    15·2 answers
  • What would a system unit that is integrated with the display and keyboard would be considered?
    6·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!