(12 / 4 * 5 / 2) = 7 ??

Why does (12 / 4 * 5 / 2) = 7 in C++ ? Does it round? Even if I declare it as a double...

-Dan
LVL 3
SuperMarioAsked:
Who is Participating?
 
jkrConnect With a Mentor Commented:
This is because you're using plain integer constants...

Try

(12.0 / 4.0 * 5.0 / 2.0)

and you should receive the expected result.
0
 
SuperMarioAuthor Commented:
Oh... *smacks forehead* Thank you so much for enlightening me!
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.