-
Notifications
You must be signed in to change notification settings - Fork 2
/
number_operation.cpp
executable file
·48 lines (42 loc) · 1.46 KB
/
number_operation.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
/*
file name: practice_exercise_4.3.cpp
This is Practice Exercise 4-3 from Blackboard.
This program takes user input of two numbers and an operation.
It completes the selected operation on the two numbers and
outputs the result.
*/
#include <iostream>
using namespace std;
int main() {
double num1, num2, total;
char operation;
cout << "Please enter two numbers: \n";
cin >> num1 >> num2;
cout << "Please enter the symbol of the requested operation: \n";
cout << "\"+\" (addition)\n";
cout << "\"-\" (subtraction)\n";
cout << "\"*\" (multiplication)\n";
cout << "\"/\" (division)\n";
cin >> operation;
switch (operation) {
case '+':
total = num1 + num2;
cout << num1 << " plus " << num2 << " equals " << total << endl;
break;
case '-':
total = num1 - num2;
cout << num1 << " minus " << num2 << " equals " << total << endl;
break;
case '*':
total = num1 * num2;
cout << num1 << " times " << num2 << " equals " << total << endl;
break;
case '/':
total = num1 / num2;
cout << num1 << " divided by " << num2 << " equals " << total << endl;
break;
default:
cout << "Invalid entry. Please try again.";
}
return 0;
}