It may have been loosely rounded earlier because floating-point numbers are not stored the same as integers and are not anywhere near as accurate or it could be something wrong with your calculations could you post more code please and show us the formula you are supposed to be using for the correct result.
As for line 30, you're right. I just need to multiple by MILE (1.609) and there's no need to divide by 1. I pulled a formula off a website and just blindly typed it in without thinking. The division by 1 was necessary for demonstrating your "work" if you were working it out on paper.
The inputs are:
Starting mileage: 300
Ending mileage: 650.45
Starting fuel in Gallons: 19
Ending fuel in Gallons: 2
You are correct. I am writing from work so I don't have access to my program, but I believe the value is 64.345 and it shows 64.34 instead of 64.35.
You may want to create a function to round it up manually then.
1 2 3 4 5 6 7
double roundHundreths( constdouble x )
double result = x * 100.0 + 0.5; //moving number 2 places right and trying to round
result = static_cast<int>( result ); //flooring
result /= 100.0; //moving number 2 places left
return( result );
example of what code does:
ex 1) 64.345
step 1: result = 64.345 * 100 + .5 = 6434.5 + .5 = 6435.0
step 2: result = 6435
step 3: result = 6435 / 100 = 64.35
ex 2) 64.344
step 1: result = 64.344 * 100 + .5 = 6434.4 + .5 = 6434.9
step 2: result = 6434
step 3: result = 6434 / 100 = 64.34
Unfortunately, my instructor specified that we are not to add any value to our results to force the rounding to happen.
I'm confused, because I am pretty sure that some of the other resulting values are rounding appropriately, but this particular value is not?! I am still at work so I don't have access to my program to confirm. Is this one having difficulty because the difference between rounding and not rounding is 0.001?
Operations of addition, subtraction, multiplication and division correspond literally to their respective mathematical operators. The last one, modulo operator, represented by a percentage sign (%), gives the remainder of a division of two values. For example:
x = 11 % 3;
results in variable x containing the value 2, since dividing 11 by 3 results in 3, with a remainder of 2.
round that up ... if the value is exactly divisible by 0.005
Honestly though I find that to be a pretty bad idea because what if it was 64.346 should that not round up also?
Also I am a bit confused when you say you can not add anything to the values when I mentioned but if you use modulus you can then round up?
Isn't rounding up adding to the value like I did? Also you could just call the function when outputting and it doesn't modify the value since not passing by reference.