When I run the program, instead of giving me some correct answer like $315.50, it will just output the closest thing like $315. |
If answer should be $315.50, then total without materials is
$315.50 - $75 = $240.50 and $240.50 / $45/h is about 5.3444444 hours
OR
total being $315.50, hours is $315.50 / $45/h = 7.0111111 hours
Did you really test with something like 5.34 or 7.01?
Then, yes, in the input you read and store only the integer part (the "whole") into the
int hour
.
Obviously 7*45.00 == 315.00 (approximately)
decimal precision
There is a different issue: floating point values are not "precise". An integer cannot hold a fraction.
Floating point numbers (float and double) have similarly only discrete possible values.
Furthermore, they have limited number of significant digits. While you can have huge number, say 3.14*10^30, adding 4.2 to it has no effect, because the result rounds to same 3.14*10^30.
An old Windows Calculator joke:
Q: What is the difference between Windows 3.11 and Windows 3.1? Should I upgrade?
A: 0
The "Calculator app" in mid 90' did calculate: 3.11 - 3.1 = 0
They had "very fine" floats back then, but the issue is still there. Floats are weird and strange.