Hello,
I am writing the code for my basic calculator program and having some issues with it.
I keep getting the same error, which doesn't let even let me see whether my program works. Could you please take a look at it and at least direct me in a direction? Any help will be appreciated
here is my code:
#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;
float num;
// Instructions function
instruct(); // Greetings and Instructions
accumVal = do_next_op(oper, num, accumVal);
cout << "Please enter the operator first and then the number or type q or Q to exit the program: " << endl;
cin << oper;
do
{ 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*/
{
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;
}*/