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
The Java compiler does not check for an ArrayIndexOutorBoundsException during the compilation of a program containing arrays. O
yulyashka [42]

Answer:

TRUE

Explanation:

  • Let us first understand what is an ArrayIndexOutOfBounds Exception.
  • As the name itself suggests the index for the array has gone out of bound (permissible value) and an exception (anamoly) is resulted.
  • So, it throws an error.
  • That means if an array, Employee of size n is defined then the permissible elements are Employee[0] to Employee[n-1]. If any negative index or with the index is greater than n-1 is tried to access it throws an error saying ArrayIndexOutOfBounds Exception.
  • In java, during the compilation of the program the compiler doesn't check for the ArrayIndexOutOfBounds Exception.It checks during running the program.
  • So, it is called a Runtime Exception.
7 0
3 years ago
How to call a void method with no parameters IN JAVA?
natka813 [3]

Explanation:

SanfoundryMenu

Java Program to Illustrate a Method without Parameters and Without Return Type

« PrevNext »

This is a Java Program to Illustrate a Method without Parameters and Without Return Type.

We have made the method to calculate area. We call this method from main method and then enter the radius of the circle as input. Now we calculate area and print the output.

Here is the source code of the Java Program to Illustrate a Method without Parameters and Without Return Type. The Java program is successfully compiled and run on a Windows system. The program output is also shown below

6 0
3 years ago
Can anybody answer this please hurry
Ludmilka [50]

Answer:

Ada Lovelace

The first one!

Hope this helps!

5 0
3 years ago
Read 2 more answers
Can some one please help me thank u.
masya89 [10]

Answer:

 A) self- evaluation

Explanation:

5 0
3 years ago
Examine the information in the URL below.
ololo11 [35]

Answer:

B The subdomain is /home/ and the domain name is http://.

Explanation:

7 0
3 years ago
Other questions:
  • Do transformers have life insurance or car insurance? If you chose life insurance, are they even alive?
    7·1 answer
  • Help pleaseeeeeeeeeeeee
    13·2 answers
  • An organization is assigned a Class-C network 200.120.80.0 and wants to form subnets for its threedepartments: D1 (60hosts), D2
    7·1 answer
  • Variable-length entities. fixed-length entities. data structures that contain up to 10 related data items. used to draw a sequen
    14·1 answer
  • The default for automatic replies in outlook is what?
    6·2 answers
  • Which of these is not enumerated as a motivation to create accessible web content?
    10·1 answer
  • Which storage device is not recommended as a permanent storage solution?
    6·1 answer
  • Discuss your role as an IT professional in terms of your responsibility to clients, co-workers and society.
    11·1 answer
  • What is the name of the directory that contains symbolic links to unix sysv rc scripts for runlevel 2?
    5·1 answer
  • In additon to setting up services, what other tasks does a sysadmin have to keep in mind? check all that apply.
    11·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!