simple calculator using function

#include<iostream>
using namespace std;
void calculate();
void choices();
void num();
int choice, a,b;
int main(){
choices();
calculate();



}
void calculate(){
switch (choice){
case 1:
num();
cout<<"the answer of addition = "<<a+b<<endl;
break;
case 2:
num();
cout<<"the answer of subtraction = "<<a-b<<endl;
break;
case 3:
num();
cout<<"the answer of multiplication = "<<a*b<<endl;
break;
case 4:
num();
cout<<"the answer of division = "<<a/b<<endl;
break;
}
}
void num(){
cout<<"enter two numbers "<<endl;
cout<<" 1st num = ";
cin>> a;
cout<<" 2nd num = ";
cin>> b;
}
void choices(){
cout<<"enter 1 to add"<<endl;
cout<<"enter 2 to subtract"<<endl;
cout<<"enter 3 to multiply"<<endl;
cout<<"enter 4 to divide"<<endl;
cin>>choice;
cout<<endl;
}
Previous
Next Post »

Comments:

Disqus Shortname