Skip to content

Instantly share code, notes, and snippets.

@edenizk
Created May 11, 2018 16:56
Show Gist options
  • Select an option

  • Save edenizk/12934bfbf46747b9ac6e928fff411233 to your computer and use it in GitHub Desktop.

Select an option

Save edenizk/12934bfbf46747b9ac6e928fff411233 to your computer and use it in GitHub Desktop.
small calculator
#include <iostream>
using namespace std;
/* run this program using the console pauser or add your own getch, system("pause") or input loop */
int main(int argc, char** argv) {
char ch,cont;
double a,b,c,d,e;
do{
cout<<"Choose Which Calculation Do You Want To Make:"<<endl
<<"a.sum(+))"<<endl
<<"b.subtraction(-)"<<endl
<<"c.multiplication(x)"<<endl
<<"d.division(:)"<<endl;
cin>>ch;
switch(ch){
case 'a' :
cout<<"you choosed sum please enter 2 number"<<endl;
cout<<"first number: ";
cin>>a;
cout<<" second number: ";
cin>>b;
c=a+b;
cout<<"the answer is: "<<c<<endl;
break;
case 'b' :
cout<<"you choosed subtraction please enter 2 number"<<endl;
cout<<"first number: ";
cin>>a;
cout<<" second number: ";
cin>>b;
c=a-b;
cout<<"the answer is: "<<c<<endl;
break;
case 'c' :
cout<<"you choosed multiplication please enter 2 number"<<endl;
cout<<"first number: ";
cin>>a;
cout<<" second number: ";
cin>>b;
c=a*b;
cout<<"the answer is: "<<c<<endl;
break;
case 'd' :
cout<<"you choosed division please enter 2 number"<<endl;
cout<<"first number: ";
cin>>a;
cout<<" second number: ";
cin>>b;
if (a<0 || a>0 || b>0 ||0>b)
{
c=a/b;
cout<<"the answer is: "<<c<<endl;
break;
}
else
cout<<"you cannot use 0"<<endl;
break;
default :
cout<<"something went wrong please re-open the app"<<endl;
}
cout<<"do you wanna continou[Y/N]"<<endl;
cin>>cont;
}while (cont=='y'|cont=='Y');
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment