ARITHMETIC CALCULATIONS USING FUNCTIONS
#include<iostream.h>
#include<conio.h>
sint menu( );
int add(int, int);
int sub(int, int);
int mul(int, int);
float div(int,
int);
void main()
{
int a,b;
cout<<"\n\n\t\tCalculator\n\n";
cout<<"\tEnter Number 1 : ";
cin>>a;cout<<"\tEnter
Number 2 : ";
cin>>b;switch(menu())
{case
1:
Cout<<"Sum
is "<<add(a,b);
break;
case 2:
cout<<"Difference
is "<<sub(a,b);
break;
case 3:
cout<<"Product
is "<<mul(a,b);
break;
case
4:cout<<"Quotient is "<<div(a,b);
break;
default:
cout<<"Invalid
Choice";
}
}
int menu()
{
int ch;
cout<<"\n\t1.Addition\n\t2.Subtraction\n\t3.Multiplication.\n\t4.Division\n\n\tEnter Your
Choice : ";
cin>>ch;
return ch;
}
int add(int a,
int b)
{
return a+b;
}
int sub(int a,
int b)
{
return a-b;
}
int mul(int a,
int b)
{
return a*b;
}
float div(int
a, int b)
{
return
(float)a/b;
}
No comments:
Post a Comment