Confusion in c++ | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

Confusion in c++

Why the output of (1/2)*5*10 is 0. It should be 25.

9th Oct 2018, 2:57 PM
Harry Kane
Harry Kane - avatar
2 Answers
+ 2
You're probably using integers. Convert at least one of them to double: (double)1/2*5*10 = 25
9th Oct 2018, 3:01 PM
Anna
Anna - avatar
+ 1
Or use 1.0/2 instead of 1, compiler will detect the type of the left operand.
9th Oct 2018, 4:04 PM
Petr Leliaev
Petr Leliaev - avatar