0

Division

when i count 9/2 is 4, the question is how to equal 4.5?

20th Feb 2017, 3:13 PM
Rafii A.
Rafii A. - avatar
1 ответ
+ 9
In terms of basic arithmetic... 9 divided by 2 is 4.5. 7 divided by 2 is 3.5. By doing 9/2 in C++, the program treats both values as integer and hence returns an integer value of 4. If you want to get 4.5, do 9.0/2.0. If you want to get 3.5, do 7.0/2.0. You may also look into float, double type variables, or read up on the usage of static_cast.
20th Feb 2017, 5:33 PM
Hatsy Rei
Hatsy Rei - avatar