Hi

I need to perogram the simple Calculatotr,
Acceptable operators.'
+ : Add
- : Subtract
* : Multiply
/ : Divide
^ : Power ( raise left oprqnd to the power of the rifgt operand )
q or Q = Quit

This is a progarm that I wrote :

#include <iostream>
#include <cmath>

using namespace std;

void Instructions();
float do_next_op(char op, float o, float
 CAV);
void startCalculatorProgram();

void main()
{
	startCalculatorProgram();
}

void Instructions()
{
	cout << "Begin Calculater " << endl;
	cout << "Instructions are:" << endl;
	
}
float do_next_op(char op, float o, float CAV)
{
	switch (op)
	{
		case '+':
			return CAV + o;
			break;
		case '-':
			return CAV - o;
			break;
		case '*':
			return CAV * o;
			break;
		case '/':
			return CAV / o;
			break;
		case '^':
			return pow(CAV, o);			
			break;
		default:
			cout << "the input you choosed is not correct" << endl;
	}

void startCalculatorProgram()
{
	Instructions();

	float accumulatedValue = 0.0;
	char op;
	float o;
	while (true)
	{
		cin >> op;
		if (op == 'q' || op == 'Q')
		{
			cout << "ByeBye..." << endl;
			break;
		}
		cin >> o;
		accumulatedValue = do_next_op(op, o, accumulatedValue);
		cout << "Result so far is " << accumulatedValue << endl;
	}

I want to build the program, and I got two errors

Error 1 error C2601: 'startCalculatorProgram' : local function definitions are illegal c:\users\nimasafa\documents\visual studio 2008\projects\nimasafaeian__cs 210 programming\nimasafaeian__cs 210 programming\nimasafaeian__cs 210 programming.cpp 46 nimasafaeian__cs 210 Programming


Error 2 fatal error C1075: end of file found before the left brace '{' at 'c:\users\nimasafa\documents\visual studio 2008\projects\nimasafaeian__cs 210 programming\nimasafaeian__cs 210 programming\nimasafaeian__cs 210 programming.cpp(46)' was matched c:\users\nimasafa\documents\visual studio 2008\projects\nimasafaeian__cs 210 programming\nimasafaeian__cs 210 programming\nimasafaeian__cs 210 programming.cpp 64 nimasafaeian__cs 210 Programming

Can you please help me out to solve my problems.
Thank you so much

Error 1: that error message always means that you have mis-matched { and } or parentheses. Count them and make correction.

Error 2: correct error #1 and this will be fixed too.

I don't know what exactly I have to do, I searched but I couldn't find my mistake, can you please correct it for me.
Thanks

You didn't look very hard did you??? Look just above the line that contains the error -- there is a missing } to close the previous function.

Actualy I did look very hard, but I'm not smart than you, what line are you exatly taking about ?

i solved the first error but i still have the second error

Error 1 fatal error C1075: end of file found before the left brace '{' at 'c:\users\nimasafa\documents\visual studio 2008\projects\gggg\gggg\gggg.cpp(45)' was matched c:\users\nimasafa\documents\visual studio 2008\projects\gggg\gggg\gggg.cpp 64 gggg

Same problem -- missing the closing } for the last function in your program.

would please correct it for me and posted in this forum, It's been 4 hours I've working on this but it doesn't work.

You can do it yourself. Just add another } at the end of the last function. One keystroke!

would please correct it for me and posted in this forum, It's been 4 hours I've working on this but it doesn't work.

All you have to do is count!!

#include <iostream>
#include <cmath>

using namespace std;

void Instructions();
float do_next_op(char op, float o, float
 CAV);
void startCalculatorProgram();

void main()
{[B]  1[/B]
	startCalculatorProgram();
}[B]  0[/B]

void Instructions()
{[B]  1[/B]
	cout << "Begin Calculater " << endl;
	cout << "Instructions are:" << endl;
	
}[B]  0 (so far so good)[/B]
float do_next_op(char op, float o, float CAV)
{[B]  1[/B]
	switch (op)
	{[B]  2[/B]
		case '+':
			return CAV + o;
			break;
		case '-':
			return CAV - o;
			break;
		case '*':
			return CAV * o;
			break;
		case '/':
			return CAV / o;
			break;
		case '^':
			return pow(CAV, o);			
			break;
		default:
			cout << "the input you choosed is not correct" << endl;
	}[B]  1[/B]

void startCalculatorProgram()
{[B]  2  (2?? This should be a 1! Something is missing above)[/B]
	Instructions();

	float accumulatedValue = 0.0;
	char op;
	float o;
commented: Nicely put +23
commented: exactly! +36
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.