-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpractice.cpp
More file actions
53 lines (49 loc) · 1.39 KB
/
practice.cpp
File metadata and controls
53 lines (49 loc) · 1.39 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
#include <iostream>
using namespace std;
int main() {
cout << "Welcome to Calculator";
int number1, number2;
cout << "\nEnter a number\n";
cin >> number1;
cout << "Enter second number\n";
cin >> number2;
char op;
cout << "Which operation do you want (+, -, *, /, %): ";
cin >> op;
switch(op) {
case '+':
cout << "Result: " << number1 + number2 << endl;
break;
case '-':
cout << "Result: " << number1 - number2 << endl;
break;
case '*':
cout << "Result: " << number1 * number2 << endl;
break;
case '/':
if (number2 != 0)
cout << "Result: " << number1 / number2 << endl;
else
cout << "Error: Division by zero" << endl;
break;
case '%':
if (number2 != 0)
cout << "Result: " << number1 % number2 << endl;
else
cout << "Error: Division by zero" << endl;
break;
default:
cout << "Invalid operation" << endl;
}
char r;
cout << "Do you want to continue or exit (y/n): ";
cin >> r;
while (r == 'y' || r == 'n') {
if (r == 'y') {
main(); // Restart the program
} else {
break;
}
}
return 0;
}