-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlesson_13.cpp
119 lines (106 loc) · 2.74 KB
/
lesson_13.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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
#include <chrono>
#include <iostream>
#include <thread>
void Clear() {
#if defined _WIN32
system("cls");
// clrscr(); // including header file : conio.h
#elif defined(__LINUX__) || defined(__gnu_linux__) || defined(__linux__)
system("clear");
// std::cout<< u8"\033[2J\033[1;1H"; //Using ANSI Escape Sequences
#elif defined(__APPLE__)
system("clear");
#endif
}
int main() {
// INFO: Swtich: altarnative to using many "else if" statements
// compare one value against matching cases
/* int month; */
/* std::cout << "Enter the month (1-12): "; */
/* std::cin >> month; */
/* switch (month) { */
/* case 1: */
/* std::cout << "It is January"; */
/* break; */
/* case 2: */
/* std::cout << "It is February"; */
/* break; */
/* case 3: */
/* std::cout << "It is March"; */
/* break; */
/* case 4: */
/* std::cout << "It is April"; */
/* break; */
/* case 5: */
/* std::cout << "It is May"; */
/* break; */
/* case 6: */
/* std::cout << "It is June"; */
/* break; */
/* case 7: */
/* std::cout << "It is July"; */
/* break; */
/* case 8: */
/* std::cout << "It is August"; */
/* break; */
/* case 9: */
/* std::cout << "It is September"; */
/* break; */
/* case 10: */
/* std::cout << "It is October"; */
/* break; */
/* case 11: */
/* std::cout << "It is November"; */
/* break; */
/* case 12: */
/* std::cout << "It is December"; */
/* break; */
/* default: */
/* std::cout << "Please enter in only numbers (1-12)"; */
/* break; */
/* } */
char op;
double num1;
double num2;
double result;
std::cout << "----------[ CALCULATOR ]----------";
std::cout << "\n\nEnter either (+ - * / %): ";
std::cin >> op;
std::cout << "\nEnter #1: ";
std::cin >> num1;
std::cout << "\nEnter #2: ";
std::cin >> num2;
std::cout << "\n----------------------------------";
std::this_thread::sleep_for(std::chrono::nanoseconds(1000));
std::this_thread::sleep_until(std::chrono::system_clock::now() +
std::chrono::seconds(1));
Clear();
std::cout << "----------[ CALCULATOR ]----------\n\n";
switch (op) {
case '+':
result = num1 + num2;
std::cout << "RESULT: " << result;
break;
case '-':
result = num1 - num2;
std::cout << "RESULT: " << result;
break;
case '/':
result = num1 / num2;
std::cout << "RESULT: " << result;
break;
case '*':
result = num1 * num2;
std::cout << "RESULT: " << result;
break;
case '%':
result = (int)num1 % (int)num2;
std::cout << "RESULT: " << result;
break;
default:
std::cout << "ERROR: INVALID OPERATOR";
break;
}
std::cout << "\n\n----------------------------------";
return 0;
}