-
Notifications
You must be signed in to change notification settings - Fork 76
/
Copy pathCPP008_Calculator_Exercise.cpp
62 lines (47 loc) · 1.41 KB
/
CPP008_Calculator_Exercise.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
/**
* Author: Tridib Samanta
* Created: 17.11.2019
**/
#include <iostream>
using namespace std;
main()
{
double var1, var2;
beginning:
cout << "Enter first number: " << endl;
cin >> var1;
cout << "Enter second number: " << endl;
cin >> var2;
cout << "What do you want to do with that numbers?" << endl;
cout << "+ - add" << endl;
cout << "- - substract" << endl;
cout << "* - multiply" << endl;
cout << "/ - divide" << endl;
char decision;
cin >> decision;
switch(decision)
{
case '+':
cout << var1 << " + " << var2 << " = " << (var1 + var2) << endl;
break;
case '-':
cout << var1 << " - " << var2 << " = " << (var1 - var2) << endl;
break;
case '*':
cout << var1 << " * " << var2 << " = " << (var1 * var2) << endl;
break;
case '/':
if (var2) //var2 != 0
cout << var1 << " / " << var2 << " = " << (var1 / var2) << endl;
else
cout << "You can't divide by 0" << endl;
break;
default:
cout << "You typed wrong character";
}
char decision2;
cout << "Do you want to continue that program? (Y/N)" << endl;
cin >> decision2;
if (decision2 == 'y' || decision2 == 'Y')
goto beginning;
}