#include <math.h> 
#include <iostream> 

using namespace std;

void instruction();
int calculator (char);
void divide_by_zero ();
float do_next_op (char, float, float);

int main()
{ 
	//input
	char input;
	float accum,num;

	// instructions ();
	void intruction();
	accum = 0 ;

	do
	{ 
		//get input 
		cout<< " : " ;
		cin >> input;
		cin >> num;
		cin.ignore();
		// Do op
		accum = do_next_op (input, num, accum);
		//display result
		cout << " Result so far : " << accum << endl;

		cout << "  "<< endl      ;
	} // end not quit
	while (input != 'Q' && input != 'q' && input != '=');

	cout << "Final result : " ;
	system ("pause") ;  
	return 0 ;
}

//instruct user 
void instruction()
{ 
	cout <<" This program models a simple calculator which can add, subtract,multiply,divide, power" << endl;
	cout << " the calculator accumulate value after each operation " << endl;
	cout << " press Q to quit the program " << endl;
	cout << " Have fun with my program " << endl<< endl;
}

float do_next_op (char op, float num, float total)
{
	switch (op)
	{
		case '+' :
			total += num;
			break;

		case '-':
			total -= num;
			break;

		case '*':
			total *= num;
			break;

		case '/': 
			total /= num;
			break;

		case '^':
			total = pow (total,num);
			break ;

		default :
			cout << " syntax error"	<< endl;
	}

	return total;
}

I sent you the code of my program and wana ask for your help because I have some problem with that
1) the program is running well, but the instructor wanna me to add in 1 more function, which I have no idea what to add in now.
2) about the input data, when I input Q, it does not quit as it should be, and when I input some weird value , I want it to display the error right after that and I tried to write many ways but it does not work ....
can you help me with that?

1) Are you going to tell us what your instructor wanted you to do, or do you expect us to read your mind ????

2) You need to make the test immediately after the line cin.ignore() to prevent the rest of the code incide that loop from executing.

Hi

1) Are you going to tell us what your instructor wanted you to do, or do you expect us to read your mind ????

from what I read in his mind :D :D :D :D :D :D

His MIND:

#include <math.h> 
#include <iostream> 

using namespace std;

void instruction();
int calculator (char);
void divide_by_zero ();
float do_next_op (char, float, float);

I have reasons to believe... that his professor asked him to implement:
these two functions too:

int calculator (char);
void divide_by_zero ();

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.