-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathSimple_Calc.cpp
125 lines (124 loc) · 2.1 KB
/
Simple_Calc.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
120
121
122
123
124
125
#include<iostream>
#include<math.h>
using namespace std;
int input()
{
int c;
cout<<"\n Choose the operation you want to perform :";
cout<<"\n 1. Add \t 2. Subtract \n 3. Multiply \t 4. Divide \n 5. Percent \t 6. Square Root \n 7. Exponential \t 0. Exit \n";
cout<<"\n Option : \t";
cin>>c;
return c;
}
int add()
{
int a, b, r;
cout<<"\n Enter first number : \t";
cin>>a;
cout<<"\n Enter second number : \t";
cin>>b;
r=a+b;
cout<<"\n The sum is : \t"<<r;
return 0;
}
int sub()
{
int a, b, r;
cout<<"\n Enter first number : \t";
cin>>a;
cout<<"\n Enter second number : \t";
cin>>b;
r=a-b;
cout<<"\n The subtraction is : \t"<<r;
return 0;
}
int multiply()
{
int a, b, r;
cout<<"\n Enter first number : \t";
cin>>a;
cout<<"\n Enter second number : \t";
cin>>b;
r=a*b;
cout<<"\n The multipication is : \t"<<r;
return 0;
}
int divide()
{
int a, b, r;
cout<<"\n Enter the dividant : \t";
cin>>a;
cout<<"\n Enter the divisor : \t";
cin>>b;
r=a/b;
cout<<"\n The quotient is : \t"<<r;
return 0;
}
int percent()
{
int a, b, r;
cout<<"\n Enter the amount : \t";
cin>>a;
cout<<"\n Enter how much % of the amount you want : \t";
cin>>b;
r=(a*b)/100;
cout<<"\n The percentage is : \t"<<r;
return 0;
}
int root()
{
int a, r;
cout<<"\n Enter the number : \t";
cin>>a;
r=sqrt(a);
cout<<"\n The root is : \t"<<r;
return 0;
}
int power()
{
int a, b, r;
cout<<"\n Enter the base number : \t";
cin>>a;
cout<<"\n Enter the exponent : \t";
cin>>b;
r=pow(a,b);
cout<<"\n The result is : \t"<<r;
return 0;
}
int result(int c)
{
switch(c)
{
case 1:
add();break;
case 2:
sub();break;
case 3:
multiply();break;
case 4:
divide();break;
case 5:
percent();break;
case 6:
root();break;
case 7:
power();break;
case 0:
cout<<"\n THANK YOU !!!";break;
default:
cout<<"\n Enter a correct option ...";break;
}
}
int main()
{
int c;
cout<<"\n \t ***** CALCULATOR ***** ";
repeat:
c=input();
result(c);
if(c!=0)
{
goto repeat;
}
return 0;
}