-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcalculator.cpp
88 lines (76 loc) · 1.52 KB
/
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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
// Kaitlyn Lavan
// October 6, 2017
// 4 function calculation code
#include <iostream>
using namespace std;
int main()
{
// variables
int num1, num2, answer;
char ops;
bool moreProcessing;
// init (always init counters, or totals)
moreProcessing = true;
// processing
while (moreProcessing == true)
{
// input
cout << " Enter equation or 0 x 0 to exit : ";
cin >> num1 >> ops >> num2;
switch (ops)
{
case 'x':
if (num1 == 0 && num2 == 0)
{
moreProcessing = false;
}
else
{
answer = num1 * num2;
cout << num1 << " " << ops << " " << num2 << " = " << answer << endl;
}
break;
case '+':
if (num1 == 0 && num2 == 0)
{
moreProcessing = false;
}
else
{
answer = num1 + num2;
cout << num1 << " " << ops << " " << num2 << " = " << answer << endl;
}
break;
case '-':
if (num1 == 0 && num2 == 0)
{
moreProcessing = false;
}
else
{
answer = num1 - num2;
cout << num1 << " " << ops << " " << num2 << " = " << answer << endl;
}
break;
case '/':
if (num1 == 0 && num2 ==0)
{
moreProcessing = false;
}
else
{
if (num1 != 0 && num2 == 0)
{
cout << "Error -- cannot divide by 0" << endl;
}
else
{
answer = num1 / num2;
cout << num1 << " " << ops << " " << num2 << " = " << answer << endl;
}
}
} // end switch
} // end while
cout << "Have a nice day!" << endl;
return 0;
}