Hello,
it the same old program calculator
i have corrected errors that were preventing me from running the program. Now that i have done it i am facing another issue; It doesnt perform needed computations such as +-* and etc. It must be my switch fn. Any help will be appreciated
#include<cmath>
#include<cmath>
#include<iostream>
#include<string>
using namespace std;
// Functions prototypes
void instruct();
char displayMenu(char);
float do_next_op(char, float, float);
int main()
{
char Q, q;
char choice; // option to the user to quit or to continue
char oper;
float accumVal = 0;;
float num;
string input;
// Instructions function
instruct(); // Greetings and Instructions
do
{
cout << "Please enter the operator first and then the number or type q or Q to exit the program: " << endl;
cin >> input;
oper= input.at(0);
accumVal = do_next_op(oper, num, accumVal);
cout << accumVal << endl;
} while (oper != 'q' || oper != 'Q');
cout << "Your Final Result is: " << accumVal << endl;
//cout << "Please type in your choice: " << endl;
//cin >> choice; //choice = displayMenu(choice); // Menu function call
system("pause");
return 0;
}
// Functions defenitions
float do_next_op(char operat, float num, float accumVal)/*The function below deteremines the
user input and does the appropriate calculations*/
{
accumVal = 0;
cout << "Please choose your command: " << operat << endl;
cin >> operat;
switch(operat)
{
case 'q': case 'Q':
cout << "Your Final Result is: " << accumVal << "Thank you for using this calculator." << endl;
break;
case '+':
accumVal += num;
cout << "Result so far: " << accumVal << endl;
break;
case '-':
accumVal -= num;
cout << "Result so far: " << accumVal << endl;
break;
case '*':
accumVal *= num;
cout << "Result so far: " << accumVal << endl;
break;
case '/':
accumVal /= num;
cout << "Result so far: " << accumVal << endl;
break;
case '^':
accumVal = pow(accumVal, num);
cout << "Result so far: " << accumVal << endl;
break;
default:
cout << "You have entered an INVALID OPERATOR! " << endl;
}
return accumVal;
}
void instruct() // Instructions
{
cout << "Welcome to this program - Calculator. This calculator was designed to ";
cout << "assist user with basic calculations. You will have a choice an option exit";
cout << "this program by simply typing q when prompted after each computation";
cout << "Thank you again and good luck in your calculations!" << endl;
}
/*bool displayMenu(bool choice) // Menu function
{
float accumVal;
switch(choice)
{
case 'q': case 'Q':
cout << "Your Final Result is: " << accumVal << "Thank you for using this calculator." << endl;
break;
}
return choice;
}*/