Sunday, 19 August 2012

calculator


#include<iostream>
#include<conio.h>
#include<math.h>
using namespace std;
using std::cin;
using std::cout;
double add(double a,double b)
{
double c;
c=a+b;
return(c);
}
double sub(double a,double b)
{
double c;
c=a-b;
return(c);
}
double mult(double a,double b)
{
double c;
c=a*b;
return(c);
}
double div(double a,double b)
{
double c;
c=a/b;
return(c);
}
double power(double a,double b)
{
double c;
c=pow(a,b);
return(c);
}
int main()
{
double y,z,i;
int x;
cout<<"*****************************\n";
cout<<"enter 1 to add 2 nos \n";
cout<<"enter 2 to sub 2 nos \n";
cout<<"enter 3 to multiply 2 nos \n";
cout<<"enter 4 to divide 2 nos \n";
cout<<"enter 5 to find power nos \n";
cout<<"*****************************\n";
cin>>x;
switch (x)
{
case 1:
{
cout<<"*****************************\n";
cout<<"enter the 2 nos to be added ";
cin>>y>>z;
i=add(y,z);
cout<<"\n"<<"the sum is"<<i;
cout<<"*****************************\n";
break;
}
case 2:
{
cout<<"*****************************";
cout<<"enter the 2 nos to be sub ";
cin>>y>>z;
i=sub(y,z);
cout<<"\n"<<"the sub is"<<i;
cout<<"*****************************";
break;
}
case 3:
{
cout<<"*****************************";
cout<<"enter the 2 nos to be multi ";
cin>>y>>z;
i=mult(y,z);
cout<<"\n"<<"mult is "<<i;
cout<<"*****************************";
break;
}
case 4:
{
cout<<"*****************************";
cout<<"enter the 2 nos to be divided ";
cin>>y>>z;
i=div(y,z);
cout<<"\n"<<"div is"<<i;
cout<<"*****************************";
break;
}
case 5:
{
cout<<"*****************************";
cout<<"enter the base and power ";
cin>>y>>z;
i=pow(y,z);
cout<<"\n"<<"the ans is"<<i;
cout<<"*****************************";
break;
}
default :
{
cout<<"*****************************";
cout<<"wrong entry";
cout<<"*****************************";
break;
}
}
getch();
}

No comments:

Post a Comment