-
Notifications
You must be signed in to change notification settings - Fork 21
/
calculator.cpp
41 lines (40 loc) · 938 Bytes
/
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
#include <bits/stdc++.h>
using namespace std;
/*
1=addition
2=subtraction
3=multiplication
4=division
*/
double calculate( double x, double y, int choice){
switch(choice){
case 1:return x+y;
case 2:return x-y;
case 3:return x*y;
case 4:return x/y;
case 99:exit(0);
default:
cout<<"Enter correct choice"<<endl;
break;
}
return 0;
}
int main(){
int choice;
cout<<"Enter your choice to perform suitable operation(99to exit)"<<endl;
cout<<"1 for addition"<<endl;
cout<<"2 for subtraction"<<endl;
cout<<"3 for multiplication"<<endl;
cout<<"4 for division"<<endl;
double x, y;
do{
cout<<"choice: ";
cin>>choice;
cout<<"Enter value of x: ";
cin>>x;
cout<<"Enter value of y: ";
cin>>y;
cout<<"result = "<<calculate(x,y,choice)<<endl;
}while(choice!=99);
return 0;
}