Hey guys so I'm trying to modify my old calculator program from previous assignments, into a calculator made of functions. What I'm struggling with is trying to make the calculator add the previous answer instead of the first number I put in. Thanks for helping!
Here's my header
1 2 3 4 5 6 7 8 9 10
#ifndef header
#define header
int Divide (int, int);
int Add (int, int);
int Mult (int, int);
int Sub (int, int);
#endif
int Add (int X, int Y)
{
return X + Y;
}
int Mult (int X, int Y)
{
return X * Y;
}
int Sub (int X, int Y)
{
return X - Y;
}
int Divide (int X, int Y)
{
return (X / Y);
}
I don't really understand the logic in some parts of your program:
- please explain what line 32 is supposed to achieve. If I choose c, the switch is not executed, but it is executed if I type C
- if you don't want to execute for c, why do you still treat the c case on line 69
- if you enter operator v, it will go to default, vop is false, prints "Enter another operator" then exits at line 87
- I REALLY hate goto statements. There might be some place for them, but you should avoid them. It makes code much harder to read
As for your question, if you really want to apply operator on the previous result, you need to replace Add(X,Y) with Add (Z,Y) and so on for Sub, Mult, and Divide