Forums
New posts
Search forums
Members
Current visitors
Log in
Register
What's new
Search
Search
Search titles only
By:
New posts
Search forums
Menu
Log in
Register
Install the app
Install
Forums
Archive
Archive
C Programming
difference between statement
JavaScript is disabled. For a better experience, please enable JavaScript in your browser before proceeding.
You are using an out of date browser. It may not display this or other websites correctly.
You should upgrade or use an
alternative browser
.
Reply to thread
Message
[QUOTE="John Gordon, post: 5021181"] This expression: (9/5) is composed entirely of integers, therefore it is computed using integer math, which discards the fractional part and evaluates to 1. So your program is really doing this calculation: fahr = -17 * 1 + 32 Which evaluates to 15. To fix this behavior, get in the habit of adding .0 after any number that you want to be treated as a float, like so: fahr = celsius * (9.0/5.0) + 32.0; This will give the correct results. (Your second example works because without the parentheses, the first operation is to multiply celsius by 9. One of those numbers is a float, so the calculation is done as a float. Then that result is divided by five, and again one of the numbers is a float, so the calculation is done as a float.) [/QUOTE]
Verification
Post reply
Forums
Archive
Archive
C Programming
difference between statement
Top