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
|
#include<iostream>
#include<conio.h>
using namespace std;
int add(int a, int b)
{
cout<<"Please enter a number"<<endl;
cin>>a;
cout<<"Please enter another number to add\n";
cin>>b;
int c = a + b;
cout<<"Output: "<<a<<" + " <<b<< " = "<<c;
return c;
}
int sub(int a, int b)
{
cout<<"Please enter a number"<<endl;
cin>>a;
cout<<"Please enter another number to subtract\n";
cin>>b;
int c = a - b;
cout<<"Output: "<<a<<" - " <<b<< " = "<<c;
return c;
}
int mul(int a, int b)
{
cout<<"Please enter a number"<<endl;
cin>>a;
cout<<"Please enter another number to multiply\n";
cin>>b;
int c = a * b;
cout<<"Output: "<<a<<" * " <<b<< " = "<<c;
return c;
}
int devide(int a, int b)
{
cout<<"Please enter a number"<<endl;
cin>>a;
cout<<"Please enter another number to devide\n";
cin>>b;
int c = a / b;
cout<<"Output: "<<a<<" / " <<b<< " = "<<c;
return c;
}
int input(int option,int a,int b)
{
while(1)
{
cout<<endl;
cout<<"-----------------------------------------------------\n"<<endl;
cout<<"Please select the option you want to perform"<<endl;
cout<<"1. Addition"<<endl<<"2. Subtraction"<<endl<<"3. Multiplication\n"<<"4. Devision\n"<<"5. Exit Calculator\n";
cout<<"\nPlease enter your option:";
cin >>option;
switch(option){
case 1:
cout<<"You have selected Addition\n";
add(a,b);
break;
case 2:
cout<<"You have selected Subtraction\n";
sub(a,b);
break;
case 3:
cout<<"You have selected Multiplication\n";
mul(a,b);
break;
case 4:
cout<<"You have selected Devision\n";
devide(a,b);
break;
case 5:
cout<<"Exiting...";
break;
default:
cout<<"Please select a valid option";
}
if (option == 5)
{
break;
}
}
}
int main()
{
cout<<"Caculator";
int option,a,b;
input(option,a,b);
getch();
return 0;
}
| |