Friday, February 20, 2009

Calculator using struct


Link of calculator.cpp

#include
#include
struct a{
double b;
double c;
double ans;
char x;
double adition (double a,double b)
{
double c=0;
c=a+b;
return c;
}
double subtraction(double a,double b)
{
double c=0;
c=a-b;
return c;
}
double multiplication(double a,double b)
{
double c=0;
c=a*b;
return c;
}
double divition(double a,double b)
{
double c;
c=a/b;
return c;
}
};

void main()
{
a obj;
cout<< endl <<"enter>>obj.b;
cout<< endl <<"enter>>obj.c;
cout<< endl <<"enter>>obj.x;
if(obj.x=='+')
{
obj.ans=obj.adition(obj.b,obj.c);
cout<< endl <<"answer>}
else if(obj.x=='-')
{
obj.ans=obj.subtraction(obj.b,obj.c);
cout<< endl <<"answer>}
else if(obj.x=='*')
{
obj.ans=obj.multiplication(obj.b,obj.c);
cout<< endl <<"answer>}
else if(obj.x=='/')
{
if(obj.c!=0)
{
obj.ans=obj.divition(obj.b,obj.c);
cout<< endl <<"answer>}
if(obj.c==0)
cout<< endl <<"answer>}
else{
cout<< endl <<"wrong>}
getch();
}

No comments:

Post a Comment