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
emmasim [6.3K]
3 years ago
13

Write a calculator program using a switch statement that: a) Prompts the user to enter two numbers b) Prompts the user to select

between the four arithmetic operations using a choice from 1-4; for example, prompt the user with: "Choose 1) for add, 2) for subtract, 3) for multiply or 4) for divide)" c) Calculates the result of performing the selected operation on the numbers, and d) Displays the answer on the screen (15 pts)
Computers and Technology
1 answer:
dlinn [17]3 years ago
5 0

Answer:

// calculator program in C++.

#include <bits/stdc++.h>

using namespace std;

// main function

int main()

{

// variables

int x,y;

int ch;

   cout<<"Enter 1st number:";

   // read first number

   cin>>x;

   cout<<"Enter 2nd number:";

   // read second number

   cin>>y;

   cout<<"Choose 1) for add, 2) for subtract, 3) for multiply or 4) for divide):";

   // read choice

   cin>>ch;

   switch(ch)

   {

       // if choice is 1, find Addition

       case 1:

       cout<<"Addition of two numbers is:"<<(x+y)<<endl;

       break;

       // if choice is 2, find subtraction

       case 2:

       cout<<"Subtract the second from the first is:"<<(x-y)<<endl;

       break;

       // if choice is 3, find multiplication

       case 3:

       cout<<"Multiplication of two numbers is:"<<(x*y)<<endl;

       break;

       // if choice is 4, find division

       case 4:

       cout<<"Division the first by the second is:"<<(x/y)<<endl;

       break;

       // if choice is other

       default:

       cout<<"Wrong choice:"<<endl;

       break;

   }

return 0;

}

Explanation:

Read two numbers from user.Then read the choice of operation from user.If choice is 1, then print the Addition of both numbers.If choice is 2, then print the subtraction. If the choice is 3, then print the multiplication.If choice is 4, then print the  division.If choice is other than these, then print wrong choice.

Output:

Enter 1st number:10                                                                                                      

Enter 2nd number:2                                                                                                      

Choose 1) for add, 2) for subtract, 3) for multiply or 4) for divide):3                                                    

Multiplication of two numbers is:20

You might be interested in
Computers help eliminate the repetitiveness of manual task how can this benefit you in your overall career?
rjkz [21]

Answer:

Explanation:

When I went to high school, our next door neighbor had a pet dinosaur. We used to have to do math problems that were incredibly long and tedious. Things like the gas laws. They involve 5 numbers with 2 decimal places and we were asked to find the 6th number.

Eventually we were taught to use log tables but by then we were too numb to care.

Computers however take repetitiveness in their stride. They don't gag at how many times they have to repeat an operation. They don't mind if they do it a thousand times or a million or 100 million times. Some algorithms like the Monte Carlo method depend on trying an operation a million times. Humans would go crazy if they had to do that. Computers can do simple algorithms a million times while the mouse is on the go command.

If you pick a job like a tax consultant, you will be glad not to do any more than knowing where the numbers that make up your data go.

Same with banks and insurance jobs. I'll bet there are many jobs in medicine that require repetitive calculations.

7 0
2 years ago
I WILL GIVE BRAINLEST!!!!!!!!
tekilochka [14]

Answer:

i think it might c but dont trust me

4 0
3 years ago
Read 2 more answers
Can someone taught me? How to use this brainy apps la?​
Anna11 [10]
Okeh, So it basically helps you find answers for you homework and stuff and you can also answer people questions too and get points. You can get brainliest answer too. You can answer fake questions too but then you can be reported and the will delete your account
6 0
3 years ago
During an engine's intake stage, what passages inside the cylinder head of a gasoline powered engine must the incoming air-and-f
kow [346]
The intake ports must be open to allow fuel and oxygen to enter cylinder, then closes during compression. Your answer is A.
3 0
3 years ago
___________is used for drawing 3D objects in the field of Science and Engineering.
Westkost [7]

Answer:

the answer is C mri hope this helps

Explanation:

6 0
2 years ago
Read 2 more answers
Other questions:
  • Do Y’all know how to view your answers to others people questions on your profile? Please answer fast
    14·1 answer
  • Can someone please help me write a code for this
    7·1 answer
  • Wice each lunar month, all year long, these tides occur. Whenever the Moon, Earth and Sun are aligned, the gravitational pull of
    5·1 answer
  • . Why should we favor programming to interfaces over implementations?
    6·1 answer
  • Question 16 (1 point)
    15·1 answer
  • Suppose there is a class Alarm. Alarm has two class variables, code which contains a String value representing the code that dea
    12·1 answer
  • Which of the following terms best describes the product development life cycle process?
    6·2 answers
  • What is the significance of the Abstract section of a research paper? A. It contains important information such as the author, c
    5·1 answer
  • How would you describe<br> "analogous color harmony" to a six year old?
    13·1 answer
  • What is the output of the code? (CHECK IMAGE)
    12·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!