I'm working on making a calculator on java, similar to the calculator have on our computers. I am stuck with trying to replicate this situation.
Computer Calculator:
5 / 2 = 2.5 * 2 = 5
so basically..
int/int = double * int = int
how does that work? lol, the closest thing I can do to that is:
int num_1 = 5;
int num_2 = 2;
double ans = (double) num_1/num_2;
double num_1 = ans;
int num_2 = 2;
int ans = num_1*num_2;
But I cannot re-declare the variable names so how do i program that...haha
In case this helps, I have 3 variables in my program:
int currentValue // value displayed when number key is pressed *** eg: 2, 3, etc
int runningValue // value of running total *** eg: 2 + 2 + (right now a runningValue of 4 is shown on the computer calculator)
int finalValue // value given when the equal sign is pressed 5 + 5 = 10
help?