Skip to content

Commit

Permalink
Created: calculator using c++
Browse files Browse the repository at this point in the history
  • Loading branch information
AdityaVSM committed Mar 3, 2021
1 parent 8406e4e commit f4ab1e9
Showing 1 changed file with 41 additions and 0 deletions.
41 changes: 41 additions & 0 deletions calculator.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,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;
}

0 comments on commit f4ab1e9

Please sign in to comment.