I've made this Calculator which can only calculate for 2 inputs only. How should I write the program, so that, the user can give multiple inputs and the calculation is performed?
And before someone asks, I use Borland C++ v5.02
Code:
/*
Work of Ashrith Babu Rao, XII
Email: a5hr1th.mb@gmail.com
(c) 2008
*/
#include <iostream.h>
#include <conio.h>
#include <math.h>
int main()
{ clrscr();
float P, R, T;
int ch;
float x,y;
char ch1;
do
{
clrscr();
cout<<"CALCULATOR:\n----------\n\n";
cout<<"SIMPLE CALCULATIONS:\n-------------------\n1: Addition\n2: Subtraction\n3: Multiplication\n4: Division\n\n"<<endl;
cout<<"SCIENTIFIC:\n----------\n5: Power\n6: Logarithm\n7: Sin\n8: Cos\n9: Tan\n10: Sin Inverse\n11: Cos Inverse\n12: Tan Inverse\n"<<endl;
cout<<"\nINTEREST CALCULATOR:\n-------------------\n13: Simple Interest\n14: Compound Interest\n\n";
cout<<"\nEnter Choice"<<endl;
cin>>ch;
if(ch==1)
{ clrscr();
cout<<"Addition\n--------\n\n";
cout<<"Enter two numbers"<<endl;
cin>>x>>y;
cout<<"\nAnswer: "<<(x+y);
}
if(ch==2)
{ clrscr();
cout<<"Subtraction\n-----------\n\n";
cout<<"Enter two numbers"<<endl;
cin>>x>>y;
cout<<"\nAnswer: "<<(x-y);
}
if(ch==3)
{ clrscr();
cout<<"Multiplication\n--------------\n\n";
cout<<"Enter two numbers"<<endl;
cin>>x>>y;
cout<<"\nAnswer: "<<(x*y);
}
if(ch==4)
{ clrscr();
cout<<"Division\n--------\n\n";
cout<<"Enter two numbers"<<endl;
cin>>x>>y;
cout<<"\nAnswer: "<<(x/y);
}
if(ch==5)
{ clrscr();
cout<<"Power ** x^y **\n---------------\n\n";
cout<<"Enter two numbers"<<endl;
cin>>x>>y;
cout<<"\nAnswer: "<<pow(x,y);
}
if(ch==6)
{ clrscr();
cout<<"Logarithm\n---------\n\n";
cout<<"Enter a number"<<endl;
cin>>x;
cout<<"\nAnswer: "<<log10(x);
}
if(ch==7)
{ clrscr();
cout<<"Sine of X\n---------\n\n";
cout<<"Enter a value"<<endl;
cin>>x;
cout<<"\nAnswer: "<<asinl(x);
}
if(ch==8)
{ clrscr();
cout<<"Cosine of X\n-----------\n\n";
cout<<"Enter a value"<<endl;
cin>>x;
cout<<"\nAnswer: "<<acosl(x);
}
if(ch==9)
{ clrscr();
cout<<"Tangent of X\n------------\n\n";
cout<<"Enter a value"<<endl;
cin>>x;
cout<<"\nAnswer: "<<atanl(x);
}
if(ch==10)
{ clrscr();
cout<<"Sine Inverse of X (Round off to nearest integer)\n------------------------------------------------\n\n";
cout<<"Enter a value"<<endl;
cin>>x;
cout<<"\nAnswer: "<<asin(x)*180/3.1416;
}
if(ch==11)
{ clrscr();
cout<<"Cosine Inverse of X (Round off to nearest integer)\n--------------------------------------------------\n\n";
cout<<"Enter a value"<<endl;
cin>>x;
cout<<"\nAnswer: "<<acos(x)*180/3.1416;
}
if(ch==12)
{ clrscr();
cout<<"Tangent Inverse of X (Round off to nearest integer)\n---------------------------------------------------\n\n";
cout<<"Enter a value"<<endl;
cin>>x;
cout<<"\nAnswer: "<<asin(x)*180/3.1416;
}
if(ch==13)
{ clrscr();
cout<<"Simple Interest\n---------------\n\n";
cout<<"Enter Principal Amount: ";
cin>>P;
cout<<"\nEnter Rate of Interest: ";
cin>>R;
cout<<"\nEnter Time Period in Years: ";
cin>>T;
cout<<"Simple Interest = Rs. "<<(P*R*T)/100;
}
if(ch==14)
{ clrscr();
cout<<"Compound Interest\n-----------------\n\n";
cout<<"Enter Principal Amount: ";
cin>>P;
cout<<"\nEnter Rate of Interest: ";
cin>>R;
cout<<"\nEnter Time Period in Years: ";
cin>>T;
cout<<"Compound Interest = Rs. "<<(P*pow((1+R/100),T)-P);
}
cout<<"\n\nEnter More?(Y/N)"<<endl;
cin>>ch1;
}while(ch1=='y');
clrscr();
cout<<"\n\nThank you for using!";
cout<<"\n(c) Ashrith Babu Rao, 2008";
getch();
}
And before someone asks, I use Borland C++ v5.02