-
Notifications
You must be signed in to change notification settings - Fork 0
/
scientific_calculator.cpp
142 lines (134 loc) · 3.4 KB
/
scientific_calculator.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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
#include <iostream>
#include <cstdlib>
#include<cmath>
using namespace std;
void addition();
void subtraction();
void multiplication();
void division();
void factorial();
void power();
void square();
void cube();
void squareroot();
int main()
{
cout << "\t\tWelcome to the scientific Calculator, developed by Tathagata Ghosh!!\n"
<< endl;
cout << "*******Press 0 to quit the program*******\n"
<< endl;
cout << "Enter 1 for Addition \n";
cout << "Enter 2 for Subtraction \n";
cout << "Enter 3 for Multiplication \n";
cout << "Enter 4 for Division \n";
cout << "Enter 5 for Power \n";
cout << "Enter 6 for Factorial \n";
cout << "Enter 7 for square \n";
cout << "Enter 8 for cube \n";
cout << "Enter 9 for squareroot\n\n";
int choice;
while (1)
{
cout << "Enter you choice: ";
cin >> choice;
switch (choice)
{
case 1:
addition();
break;
case 2:
subtraction();
break;
case 3:
multiplication();
break;
case 4:
division();
break;
case 5:
power();
break;
case 6:
factorial();
break;
case 7:
square();
break;
case 8:
cube();
break;
case 9:
squareroot();
break;
case 0:
exit(0);
break;
default:
cout << "\n*******Wrong choice, Enter valid choice*******\n\n";
break;
}
}
return 0;
}
void addition(){
cout<<"Enter the numbers you want to add: ";
int a,b;
cin>>a>>b;
cout<<"The addition of "<<a<<" and "<<b<<" is "<<a+b<<endl;
}
void subtraction(){
cout<<"Enter the numbers you want to subtract: ";
int a,b;
cin>>a>>b;
cout<<"The subtraction of "<<a<<" and "<<b<<" is "<<a-b<<endl;
}
void multiplication(){
cout<<"Enter the numbers you want to multipliation: ";
int a,b;
cin>>a>>b;
cout<<"The multiplication of "<<a<<" and "<<b<<" is "<<a*b<<endl;
}
void division(){
cout<<"Enter the numbers you want to divide: ";
int a,b;
cin>>a>>b;
cout<<"The division of "<<a<<" and "<<b<<" is "<<(float)a/(float)b<<endl;
}
void factorial(){
cout<<"Enter the number you want the factorial of: ";
int n;
cin>>n;
int fact=1;
for(int i=1;i<=n;i++){
fact=fact*i;
}
cout<<"The factorial of "<<n<<" is "<<fact<<endl;
}
void power(){
cout<<"Enter the base and exponent: ";
double b,e;
cin>>b>>e;
double power = pow(b,e);
cout<<"The solution for base "<<b<<" and exponent "<<e<<" is "<<power<<endl;
}
void square(){
cout<<"Enter the number you want the sqaure of: ";
double b;
cin>>b;
double power = pow(b,2);
cout<<"The square of "<<b<<" is "<<power<<endl;
}
void cube(){
cout<<"Enter the number you want the cube of: ";
double b;
cin>>b;
double power = pow(b,3);
cout<<"The cube of "<<b<<" is "<<power<<endl;
}
void squareroot(){
cout<<"Enter the number you want the square root of: ";
double n;
cin>>n;
double squareRoot = sqrt(n);
cout<<"The Square root of "<<n<<" is "<<squareRoot<<endl;
}