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
Create a class named CarRental that contains fields that hold a renter's name, zip code, size of the car rented, daily rental fe
Anarel [89]

Answer:

Here is the corrected code: The screenshot of the program along with its output is attached. The comments are written with each line of the program for better understanding of the code.

CarRental.java

public class CarRental  {  //class name

//below are the data members name, zipcode, size, dFee, days and total

String name;  

int zipcode;

String size;

double dFee;

int days;

double total;  

public String getName()  {  //accessor method to get the name

return name; }

public int getZipcode()  { //accessor method to get the zipcode

return zipcode; }

public String getSize() {  //accessor method to get the size

return size; }

public int getDays() {  //accessor method to get the days

return days;  }

public CarRental(String size)  {  //constructor of CarRental class

if(size.charAt(0)=='e')  // checks if the first element (at 0th index) of size data member is e

     dFee = 29.99;  // sets the dFee to 29.99

  else if(size.charAt(0)=='m')  // checks if the first element (at 0th index) of size data member is m

     dFee = 38.99;  // sets the dFee to 38.99

  else   // checks if the first element (at 0th index) of size data member is f

     dFee =43.50;  // sets the dFee to 43.50

   }

public void calculateTotal(int days) {  //method calculateTotal of CarRental

total = dFee*days;  }  //computes the rental fee

public void print()   {  //method to display the total rental fee

System.out.println("Your rental total cost is: $" + total);  } }

Explanation:

LuxuryCarRental.java

import java.util.*;

public class LuxuryCarRental extends CarRental {  //class LuxuryCarRental that is derived from class CarRental

public LuxuryCarRental(String size, int days) {  // constructor of LuxuryCarRental

super(size);}   //used when a LuxuryCarRental class and CarRental  class has same data members i.e. size

public void calculateTotal() {  //overridden method

super.calculateTotal(days); // used because CarRental  and LuxuryCarRental class have same named method i.e.  calculateTotal

dFee = 79.99;  //sets the rental fee at $79.99 per day

total = dFee;  }  //sets total to rental fee value

public void print(){  //overridden method

   int chauffeur;  // to decide to include chauffeur

Scanner keyboard = new Scanner(System.in);  //used to take input from user

System.out.println("Do you want to add a chauffeur for $200? Enter 0 for"

+ " yes and 1 for no");  // prompts the user to respond to the option of including a chauffeur at $200 more per day

chauffeur = keyboard.nextInt();   //reads the input option of chauffeur from user

if(chauffeur==1)  //if user enters 1 which means user does not want to add a chauffeur

total = dFee;  //then set the value of dFee i.e.  $79.99  to total

else  //if user enters 0 which means user wants to add a chauffeur

total = dFee + 200;  //adds 200 to dFee value and assign the resultant value to total variable

System.out.println("Your rental total cost is: $" + total);  }  } //display the total rental fee

UseCarRental.java

import java.util.*;

public class UseCarRental{ //class name

public static void main(String[] args){ //start of main() function body

String name, size; // declare variables

int zipcode, days; //declare variables

Scanner keyboard = new Scanner(System.in); // to take input from user

System.out.println("Enter total days you plan on renting: "); //prompts user to enter total days of rent

days = keyboard.nextInt(); // reads value of days from user

System.out.println("Enter your name: "); //prompts user to enter name

name = keyboard.next(); //reads input name from user

System.out.println("Enter your billing zipcode: "); // prompts user to enter zipcode

zipcode = keyboard.nextInt(); //reads input zipcode from user

System.out.println("Enter the size of the car: "); // prompts user to enter the value of size

size = keyboard.next(); //reads input size from user

CarRental economy = new CarRental(size); //creates an object i.e. economy of class CarRental

economy.calculateTotal(days); //calls calculateTotal method of CarRental using instance economy

economy.print(); //calls print() method of CarRental using instance economy

LuxuryCarRental fullsize = new LuxuryCarRental(size, days);  //creates an object i.e. fullsize of class LuxuryCarRental

fullsize.calculateTotal();  //calls calculateTotal method of LuxuryCarRental using instance fullsize

fullsize.print(); }} //calls print() method of LuxuryCarRental using instance fullsize      

4 0
3 years ago
Determine the number of bytes necessary to store an uncompressed RGB color image of size 640 × 480 pixels using 8, 10, 12 and 14
dexar [7]

Answer:

For 8 bits / Color Channel: 921, 600 bytes.

For 10 bits / Color Channel: 1,152,000 bytes.

For 12 bits / Color Channel: 1,382,400 bytes.

For 14 bits / Color Channel : 1,612, 800 bytes.

Explanation:

Un uncompressed RGB color image of 640 pixels wide by 480 pixels height (VGA resolution) uses 3 samples of x bits fin order to represent the quantity of each primary color (red, green and blue) in a given pixel of the image.

So, if we use 8 bits/ sample, we can calculate the bytes needed to store a complete image as follows:

640*480*3*8 bits = 7, 372,800 bits. (1)

As, by definition, 1 byte= 8 bits, we have:

Nº of bytes = 7,372,800 / 8 = 921,600 bytes. (2)

In order to get the bytes needed to store the same image, using 10, 12 and 14 bits/ sample, all we need is replacing 8 by 10, 12 and 14 in (1), and then dividing by 8 as in (2).

Proceeding in this way we obtain:

640*480*3*10 = 9,216,000 bits ⇒    1,152,000 bytes.

640*480*3*12 = 11,059,200 bits ⇒   1,382,400 bytes.

640*480*3*14=   12,902,400 bits ⇒  1,612,800 bytes.

8 0
3 years ago
John would like to move from the suburbs into the city, but the rent in the city is very high. John has found an apartment he re
maxonik [38]

A list of multiple choices is given;

<span>a)      </span>Purchase a home in the city center instead.

<span>b)      </span>Rent the apartment anyway.

<span>c)       </span>Rent the apartment with a roommate.

<span>d)      </span>Purchase a home in the suburbs instead.


The answer is (C)


John should look for an apartment and share it with a roommate. This will bring down rent expenses to 50% as both John and the roommate will be cost sharing the rent. If the rent expenses go down by 50%, he’ll be able to save an additional 10% and use it for other expenses.

4 0
3 years ago
A ____________ would be a misconfiguration of a system that allows the hacker to gain unauthorized access, whereas a____________
Lynna [10]

Answer:

vulnerability, risk

Explanation:

A vulnerability would be a misconfiguration of a system that allows the hacker to gain unauthorized access, whereas a risk is a combination of the likelihood that such a misconfiguration could happen, a hacker’s exploitation of it, and the impact if the event occurred.

6 0
3 years ago
Websites can have good content for a particular set of search phrases, yet rank poorly. Issues that may cause this to occur incl
raketka [301]

Answer:

B. deep organizational structure

Explanation:

A website with a deep organizational structure is a positive attribute that improves site performance.

5 0
3 years ago
Other questions:
  • Define a function CoordTransform() that transforms its first two input parameters xVal and yVal into two output parameters xValN
    7·2 answers
  • Using the Invert Selection tool while something is selected in Paint will __________.
    14·1 answer
  • The amount of data produced worldwide is increasing by ___% each year.
    5·1 answer
  • Write a pseudocode thats accept and then find out whether the number is divisible by 5 ​
    6·1 answer
  • 2) Search the Web for two or more sites that discuss the ongoing responsibilities of the security manager. What other components
    15·1 answer
  • What is a slide master ?
    8·2 answers
  • A healthcare organization received notification that a hospital employee’s laptop that contained PHI was inadvertently left at a
    14·1 answer
  • What is an operating system?<br>​
    11·2 answers
  • How many constructors are there in the following class declaration?class CashRegister { public: CashRegister(); CashRegister(int
    8·1 answer
  • Here’s my last question
    12·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!