- 1

Why it's printing int value as it is float data type

https://code.sololearn.com/cemsbvw4F8y5/?ref=app

5th Aug 2020, 5:24 AM
Gireesh Desineni
Gireesh Desineni - avatar
6 odpowiedzi
+ 11
Gireesh Desineni In your code you declared A ,B ,C; As int that's why it's output is in int. If you want your output in float then you have to declare float A,B,C;
5th Aug 2020, 5:30 AM
Vinesh Wadhwani
Vinesh Wadhwani - avatar
+ 3
In your program variable A,B and C you defined int type but in( gain ) variable u defined float data type so after calculation it will give float values if u will define gain as a int like (int gain) then answer will give int value
5th Aug 2020, 6:33 AM
A S Raghuvanshi
A S Raghuvanshi - avatar
+ 2
You can either change the values during declaration to be float or you can type cast the result to float Line 9 float gain =(float)((C-A-B)*100)/(A+B);
5th Aug 2020, 5:35 AM
Jkim Avatar
Jkim Avatar - avatar
0
XXX yeah but it is printing int value try with 4700 800 5800
5th Aug 2020, 5:28 AM
Gireesh Desineni
Gireesh Desineni - avatar
0
Gireesh Desineni sorry, I misunderstood. It is because on the RHS you are dividing an int by an int which is also an int. Try changing A, B and C to float.
5th Aug 2020, 5:32 AM
XXX
XXX - avatar
0
Input the numbers with a decimal point in them. For example 4700.0 800.0 5800.0
5th Aug 2020, 5:37 AM
XXX
XXX - avatar