-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMain.cpp
More file actions
executable file
·93 lines (67 loc) · 1.48 KB
/
Main.cpp
File metadata and controls
executable file
·93 lines (67 loc) · 1.48 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
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
89
90
91
/*
* Main.cpp
*
* Created on: Nov 17, 2014
* Author: explicitname
* purpose: To calculate simple arithmetic.
*/
#include <iostream>
using namespace std;
// Defining Arithmetic Functions
float add (float num1, float num2)
{
return num1 + num2;
}
float sub (float num1, float num2)
{
return num1 - num2;
}
float mul (float num1, float num2)
{
return num1 * num2;
}
float div (float num1, float num2)
{
return num1 / num2;
}
int main()
{
// Variable Declaration
float num1, num2, sum;
char oper;
char cont = 'y';
// Flow Control - Continues until variable cont is not equal to 'y'
do {
cout << "Josh's Simple Calculator" << endl;
cout << "Sample Format: 1 + 1 or 2 - 2" << endl;
cout << "Please Enter Statement: " << endl;
cin >> num1 >> oper >> num2;
if (!num1 || !num2) {
cout << "Error! You must use numbers!" << endl;
return 0;
}
else if (oper == '+') {
sum = add (num1,num2);
cout << "The sum is: " << sum << endl;
}
else if (oper == '-') {
sum = sub (num1,num2);
cout << "The difference is: " << sum << endl;
}
else if (oper == '/') {
sum = mul (num1,num2);
cout << "The quotient is: " << sum << endl;
}
else if (oper == '*') {
sum = div (num1,num2);
cout << "The product is: " << sum << endl;
}
else {
cont = 'n';
}
cout << "Would you like to continue? " << endl;
cout << "Enter y to continue or n to stop: ";
cin >> cont;
} while (cont == 'y' || cont == 'Y');
return 0;
}