Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Write a C++ program which prompts the user to enter two numbers and a choice of operation and then displays the result of applying the

Write a C++ program which prompts the user to enter two numbers and a choice of operation and then displays the result of applying the operation to the numbers.

Requirements:

The program is only required to work if the numbers entered by the user are integers. All calculation done in the program should be using integer values.

The program should accept numbers that are positive, negative, or zero. If the second number is zero and the selected operation is division, then the program must not attempt the division, but instead display a message as shown in the sample run below.

Valid choices for the operation are 1, 2, 3 or 4 if the user enters an invalid choice, the program must quit with a message as shown in the sample run below. Name the source file for your program program1.cpp

The prompts and output displayed by the program must be formated as shown in the sample runs below (e.g. blank lines, spacing, case of text).

A sample run of your program should look like:

This program will prompt for two integers and an operation and then display the result of applying the operation to the numbers.

Enter the first integer: 4

Enter the second integer: 9

The available operations are:

1. addition

2. subtraction

3. multiplication

4. division

Enter the number for your choice of operation: 2

4 - 9 = -5

(The numbers 4, 9 and 2 are entered by the user.)

A sample run that quits due to invalid input should look like:

This program will prompt for two integers and an operation and then display the result of applying the operation to the numbers.

Enter the first integer: 36

Enter the second integer: 4

The available operations are:

1. addition

2. subtraction

3. multiplication

4. division

Enter the number for your choice of operation: 12

12 is an invalid operation. Valid choices were 1, 2, 3 or 4. Quitting program.

(The numbers 36, 4 and 12 are entered by the user.)

A sample run that avoids a divide-by-zero error should look like:

This program will prompt for two integers and an operation and then display the result of applying the operation to the numbers.

Enter the first integer: 88

Enter the second integer: 0

The available operations are:

1. addition

2. subtraction

3. multiplication

4. division

Enter the number for your choice of operation: 4

88 / 0 can not be found because cant divide by zero.

(The numbers 88, 0 and 4 are entered by the user.)

Hints: Before you start writing the program, think about these questions:

How many variables will you need to use?

Do the variables need to be initialized?

What data type should each variable have?

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Intelligent Databases Object Oriented Deductive Hypermedia Technologies

Authors: Kamran Parsaye, Mark Chignell, Setrag Khoshafian, Harry Wong

1st Edition

0471503452, 978-0471503453

More Books

Students also viewed these Databases questions

Question

List at least three disadvantages to using a consultant.

Answered: 1 week ago

Question

How are arbitrators credentialed?

Answered: 1 week ago