Question #38105

how can i add maximum numbers to calculate ?
and i have problem in % .. how can i make "enter the second number " disappear in % operation ? :v
this is my cal :

#include <iostream>
#include <math.h>
using namespace std;

int main()
{
double num, den, result;
char op;
do {
cout <<"\nCalculator - Enter Number: ";
cin >> num;
cout << "Enter operator : +,-,*,/,^,% : ";
cin >> op;
cout << "enter second number: " ;
cin >> den;
if (op=='+') result=num+den;
if (op=='-') result=num-den;
if (op=='*') result=num*den;
if (op=='/') result=num/den;
if (op=='^') result=pow(num,den);
if (op=='%') result=num/100;

cout << result;


}
while (op!='e') ;
return 0;
}
1

Expert's answer

2014-01-13T14:36:58-0500
#include <iostream>
#include <math.h>
using namespace std;
int main()
{
    double num=0, den=0, result=0, max=256;
    char op;
    do {
        cout<<"\nCalculator - Enter Number: ";
        cin>>num;
        if(num>max){cout<<endl<<"You have exceeded the maximum number of!";}
        else{cout<<"Enter operator : +, -, *, /, ^, % : ";
            cin>>op;
            if (op!='%'){cout<<"enter second number: "; cin>>den;}
            if(den>max){cout<<endl<<"You have exceeded the maximum number of!";}
            else{
                if (op=='+') result=num+den;
                if (op=='-') result=num-den;
                if (op=='*') result=num*den;
                if (op=='/') result=num/den;
                if (op=='^') result=pow(num, den);
                if (op=='%') result=num/100;
                cout<<endl<<"Result: "<<result;
            }
        }
        cout<<endl<<"Exit? y/n"<<endl;
        cin>>op; if(op=='y'){return 0;}
    }
    while (1);
    return 0;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!
LATEST TUTORIALS
APPROVED BY CLIENTS