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:
#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;
}
Comments
Leave a comment