-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSimple_Calc.cpp
More file actions
74 lines (59 loc) · 1.61 KB
/
Simple_Calc.cpp
File metadata and controls
74 lines (59 loc) · 1.61 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
// Simple_Calc.cpp : This file contains the 'main' function. Program execution begins and ends there.
//
#include <iostream>
#include <stdlib.h>
int main()
{
int cnt = 1;
double v1 = 1;
double v2;
int op;
std::cout << "Welcome to the Simple C++ Calculator by Cylicon!\n";
while (cnt == 1) {
std::cout << "Enter your first number: ";
std::cin >> v1;
std::cout << "Enter your next number: ";
std::cin >> v2;
std::cout << "Choose your operation\n";
std::cout << " Press 1 to add, 2 to subtract, 3 to multiply and 4 to divide: ";
std::cin >> op;
switch (op) {
case 1:
std::cout << "Your answer is: " << v1 + v2 << "\n";
break;
case 2:
std::cout << "Your answer is: " << v1 - v2 << "\n";
break;
case 3:
std::cout << "Your answer is: " << v1 * v2 << "\n";
break;
case 4:
std::cout << "Your answer is: " << v1 / v2 << "\n";
break;
default:
std::cout << "Error: Unsupprted character/numerical. Please type correct numericals and choose from the four options given above.\n";
break;
}
std::cout << "Do you wish to continue?\n";
std::cout << "Press 0 to exit or 1 to continue: ";
std::cin >> cnt;
if (cnt == 0) {
std::cout << "Thanks for using calc!\n";
void exit();
system("pause");
}
}
while (cnt > 1 || cnt < 0) {
std::cout << "Error: Unsupprted character/numerical. Please type correct numericals and choose from the two options given above.\n";
std::cout << "Do you wish to continue?\n";
std::cout << "Press 0 to exit or 1 to continue: ";
std::cin >> cnt;
if (cnt == 1) {
return main();
}
else {
void exit();
}
system("pause");
}
}