Hello, I am trying to make a calculator that does multiplication, division, addition and subtraction. My problem is that when I have the two numbers that have decimals it goes wonky. Anyway, that program runs like this:
1. User enters equation
2. Unwanted characters get thrown out
3. If operation detected, send the equation string and the operation character to a function that does this:
1. Finds how many characters to the left the number is (how long)
2. Does the same for the right side
3. Does the operation accordingly by converting the numbers to double, adding (or whatever it is doing) the numbers, and converting back. The problem is converting back to string.
here is the bad code (this part is the same for every operation except what happens to the numbers):
double add1; double add2; double ans; add1 = atof (num1); add2 = atof (num2); ans = add1 + add2; itoa(ans, bufadd, 10);
num1 is the number on the left of the operator. It is a string
num2 is for the left side
bufadd is where the answer is converted back to a string. later, it gets injected back into the actual equation, all spaces get filled up, and the search for another operator repeats.
Is there any easy fix?
Edited by mitch9654: n/a