So far ive been able to read expressions from textfile and calculate them, but only single digit numbers. how can i modify it to read two also? Any help would be much appreciated!
My input from file:
My outputfile (which did not output the last expression correctly, it's only reading one digit):
Press any key to continue . . .
Answer: 3 + 5 = 8
Answer: 4 * 5 = 20
Answer: 2 - 8 = -6
int multFunction (int, int);
int divFunction (int, int);
int addFunction (int, int);
int subtractFunction (int, int);
int modFunction (int, int);
int main (void)
int iochar, operand1=0, operand2=0;
int calc, answer;
your while loop processes one character at a time, but your mechanism for extracting operand 1 & 2 does not cater correctly for more than one charactor.
ie: the code:
1 2 3 4
does not apply a "Weight" (a power of 10) to the character being decoded and add to operand - instead it replaces any previous value stored in it.
Either you should keep some state (or derive) of what the weight should be per cycle for building your operands or you could simplify your program to read entire line into string, then find position of math symbol (+,-,*,/).
Once the position of this symbol is found you can store the part before it into a string for operand1 nd the part after into operand2.
To convert your string operands [say strOp1] to the integer operand operand1 you can do the following: