Need help with command line calcuator



CommandLineCalc& CommandLineCalc::operator=(const double &other)
{
int power = 1;
int temp = (int) other;
double decimal = other - (double) temp;
while(decimal - (int) decimal != 0){ // || decimal != (int) decimal
decimal *= 10;
power *= 10;
}
nume = (int) decimal;
deno = power;
nume += (temp * power);
reduce();
}





This is part of command calculator that I'm working on for my class. It supposed to work up to 7 decimal places but it doesn't work after second decimal. While loop from code right above seems to be the code that I need to work on. May I please get help with this?? :/
What does your command calculator calculate?
It is regular calculator that calculates decimals and print out result as fraction(if needed) (ex. 1.25 + 2.25 = 7/2)

It handles positive and negative numbers, integers and real numbers that have comma separators, as well as multiple decimal points correctly and/or operators and/or fraction "slashes."

But it doesn't accept decimals for some reason
What is your expected output then?
Expected output is fraction or integer of input value(decimal +-*/ decimal - decimals up to 7 decimal places) but seems like it doesn't work with 2nd decimal places. It does print any value if I plug in 2.56 + 2.13 for example. Professor said that I have to work on my While loop above but I can't find solution for that
Last edited on
I want real values and real output examples, so don't give me formula.
http://imgur.com/3KyJu9b

There are 2 items on the command line
They are:
argv[0] : C:\Users\Jun\Documents\build-CLC-Desktop_Qt_5_7_0_MinGW_32bit-Debug\debug\CLC.exe
argv[1] : /o=+
Expression (number , number): 1.5 + 2.5
You entered: 1.5 + 2.5
First = 3/2, op = +, Second = 5/2
Result: (3/2) + (5/2) = 4
Expression (number , number): 1.25 + 2.25
You entered: 1.25 + 2.25
First = 5/4, op = +, Second = 9/4
Result: (5/4) + (9/4) = 7/2
Expression (number , number): 1.325 + 4.322
You entered: 1.325 + 4.322

this is the example the jpg is just a screenshot of whats written below
Topic archived. No new replies allowed.