-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcalculator.cpp
More file actions
29 lines (28 loc) · 1.01 KB
/
calculator.cpp
File metadata and controls
29 lines (28 loc) · 1.01 KB
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
#include <iostream>
using namespace std;
main() {
cout << "What type of math do you want to do?(1 = Addition, 2 = Subtraction, 3 = Multiplication, 4 = Division)" << endl;
int mathtype;
cin >> mathtype;
float num1, num2;
cout << "Please input the first number" << endl;
cin >> num1;
cout << "Please input the second number" << endl;
cin >> num2;
float ans;
if (mathtype == 1) {
ans = num1 + num2;
cout << "The sum of " << num1 << " and " << num2 << " is " << ans;
} else if (mathtype == 2) {
ans = num1 - num2;
cout << "The difference of " << num1 << " and " << num2 << " is " << ans;
} else if (mathtype == 3) {
ans = num1 * num2;
cout << "The product of " << num1 << " and " << num2 << " is " << ans;
} else if (mathtype == 4) {
ans = num1 / num2;
cout << "The quotient of " << num1 << " and " << num2 << " is " << ans;
} else {
cout << "Error, invalid math type";
}
}