## Se7Olutionyg -7

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

using namespace std;

void instruction();
float clean (char , float ,float );
float do_next_op (char, float, float);
float clean1 (char input, float num);
int main()
{
//input
char input;
float accum,num;

// instructions ();
void instruction();
float clean (char op1, float total,float num);
float clean1 (char input, float num);
accum = 0 ;

do
{
//get input
cout<< " : " ;
cin >> input;
cin >> num;

// CHECK NUMBER
if (cin.fail())
{
cerr << "num is invalid" <<  ". Result so far : " << accum << endl <<endl;
cin.clear();
while (cin.get() != '\n') {}; // get all characters from buffer -> clear buffer
}
else // 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 : " << accum<< endl;
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 '/':

// CHECK DIVIDE BY ZERO
if (num == 0)
{
cerr << "Divide by zero" << endl;
}
else total /= num;
break;

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

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

}
//clean function

float clean (char op1, float num1, float total1)
{
switch (op1)
{
case 'C':
total1 = 0;
cout << " : " ;
cin >> total1;
break ;

}
}
float clean1 (char input, float num)

while ......
(input != 'C' && input != 'c' );