
Patrick B. answered 07/01/21
Math and computer tutor/teacher
using namespace std;
#include <iostream>
#include <string.h>
#include <math.h>
char menuOperation()
{
char chOp='?';
char strOp[]="+-*/\\%^qQ";
while (strchr(strOp,chOp)==NULL)
{
cout << " Input one of the following operation characters " << endl;
cout << " or Q to QUIT :" << endl;
cout << " + " << endl;
cout << " - " << endl;
cout << " * " << endl;
cout << " / " << endl;
cout << " ^ " << endl;
cout << " -- # :>";
cin >> chOp;
}
return(chOp);
}
Go()
{
char chOp='?';
double A,B;
cout << "Please input the 1st number :>";
cin >> A;
while (chOp != 'Q' && chOp!='q')
{
chOp = menuOperation();
if (chOp=='Q' || chOp=='q')
{
break;
}
cout << "Please input the next number :>";
cin >> B;
switch (chOp)
{
case '+': { A+=B; break; }
case '-': { A-=B; break; }
case '*': { A*=B; break; }
case '^': { A = pow(A,B); break; }
case '/':
{
if (B!=0)
{
A/=B;
}
else
{
cout << "division By ZER0 " << endl;
}
break;
}
} //switch
cout << "subtotal is " << A << endl;
} //while
cout << "Final result is " << A << endl;
}
main() { Go(); }