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;
	
}*/

Recommended Answers

All 3 Replies

This belongs in the C++ forum, not Geeks lounge.
That said, what error do you get? You should read and heed error messages. Even if you don't fully understand what it's saying, it should point you to the neighborhood of the problem.

You call do_next_op( ) before you've gottne any values. You have the >> pointing wrong way on a cin statement.

Your do...while is not surrounding all the actions that should be inside it.

That should get you started.

(Mods - could you move this to correct forum? tia)

Moved to the C++ forum.

Sorry,
was too tired to realize where i was posting
thanks for heads up

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.