-
Notifications
You must be signed in to change notification settings - Fork 0
/
simple_calculator.cpp
67 lines (65 loc) · 2.1 KB
/
simple_calculator.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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
// Calculator used for simple calculations; addition,
// subtraction, multiplication, division, and remainder
#include <iostream>
int main(){
std::cout << "Welcome to the basic calculator!\n";
std::cout << "You will first choose two numbers,\n";
std::cout << "then you will tell me what calculation you\n";
std::cout << "wish to perform on those two numbers by\n";
std::cout << "typing in the symbol corresponding to that calculation.\n";
std::cout << "For instance if you wanted to add the numbers 2 and 4 together\n";
std::cout << "you would give me the numbers 2 and 4\n";
std::cout << "then when prompted give me the symbol '+'.\n";
std::cout << "After a quick behind-the-scenes calculation\n";
std::cout << "I will give you the answer.\n";
// Start by gathering user input
double a;
double b;
// Get user's numbers
std::cout << "Input your first number here: \n";
std::cin >> a;
std::cout << "Input your second number here: \n";
std::cin >> b;
// Get user's desired calculation
std::cout << "Insert the symbol corresponding to your desired calculation\n";
std::cout << "using the symbols +, -, /, or *: \n";
char c;
std::cin >> c;
// Calculate the user's request
double calc;
if (c == '+'){
calc = a + b;
}
else if (c == '-'){
calc = a - b;
}
else if (c == '/'){
calc = a / b;
}
else if (c == '*'){
calc = a * b;
}
else{
std::cout << "You entered an invalid character, please try again...\n";
return 0;
}
std::cout << calc << std::endl;
return 0;
}
// # Get user's desired calculation
// print("Insert the symbol corresponding to your desired calculation")
// print("using the symbols +, -, /, or *: ")
// c = input()
// # calculate the user's request
// if c == '+':
// calc = num_1 + num_2
// elif c == '-':
// calc = num_1 - num_2
// elif c == '/':
// calc = num_1 / num_2
// elif c == '*':
// calc = num_1 * num_2
// else:
// print("You entered an invalid character, please try again...")
// quit()
// print(calc)