Answer to Question #180223 in C++ for Rose

Question #180223

Complete a program that allows the user to choose addition or subtraction operations on two numbers entered from the keyboard.

Input

1.Choice of operation

2.First number

3.Second number

Process

If choose to perform operation, add two numbers; otherwise, subtract two numbers

Output

Result of operation

Sample Output

Enter your choice, 1 for Addition, 2 for subtraction:

Enter first number

Enter second number

The result of the operation is:



1
Expert's answer
2021-04-11T15:53:10-0400
#include <iostream>


using namespace std;


int main()
{
    cout << "Enter your choice, 1 for Addition, 2 for subtraction:";
    int choice;
    cin >> choice;


    cout << endl << "Enter first number: ";
    double firstNumber;
    cin >> firstNumber;


    cout << endl << "Enter second number: ";
    double secondNumber;
    cin >> secondNumber;


    double resultOfOperation;
    if(choice == 1)
        resultOfOperation = firstNumber + secondNumber;
    else
        resultOfOperation = firstNumber - secondNumber;


    cout << endl << "The result of the operation is: " << resultOfOperation << endl;


    return 0;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS