Program for Four Function Calculator
#include <iostream.h>
#include <conio.h>
int main()
{
float a,b,c,d,e;
char op,option;
cout<<"Enter value of a= ";
cin>>a;
cout<<"Enter value of b= ";
cin>>b;
cout<<"Enter value of c= ";
cin>>c;
cout<<"Enter value of d= ";
cin>>d;
cout<<"First Fraction="<<a<<"/"<<b;
cout<<"\nSecond Fraction="<<c<<"/"<<d;
cout<<"\nEnter operator= ";
cin>>op;
switch(op)
{
case '+':
cout<<"Formula= (a/b)+(c/d)= (a*d +b*d)/b*c";
e=(a*d+b*d)/(b*c);
cout<<"\nAnswer= "<<e;
break;
case '-':
cout<<"Formula= (a/b)-(c/d)= (a*d -b*d)/b*c";
e=(a*d-b*d)/(b*c);
cout<<endl<<"Answer= "<<e;
break;
case '*':
cout<<"Formula= (a/b)*(c/d)= (a*c /b*d)";
e=((a*c)/(b*d));
cout<<endl<<"Answer= "<<e;
break;
case '/':
cout<<"Formula= (a/b)/(c/d)= (a*d/b*c)";
e=((a*d)/(b*c));
cout<<endl<<"Answer= "<<e;
break;
default:
("Unknown Operator");
}
getch();
return 0;
}
No comments :
Post a Comment