Code coach Halloween Candy. | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Code coach Halloween Candy.

Hi. It takes first input 3. When you calculate it, you see 67,65 on calculator. So the code shows us integer and the answer should be 67. But it returns 66 and I couldn't solve it. What am I missing? Thanks in advance. https://code.sololearn.com/c1gxl3XphW58/?ref=app Edit: I understood that java take the number as integer after every single operation, not at the end. Normally, 200/3+99/100=67.66 --> 67 (as integer) Java makes it this way; 200/3=66.66 --> 66 (as integer) 99/100=0.99 --> 0 (as integer) 66+0=66 That's why not 67. 👆🏻

15th Dec 2021, 8:58 AM
isaac
2 Answers
0
int chance = (int) (Math.ceil(2.0*100/houses)); Use this line. Because as you need to take it to nearest integer
15th Dec 2021, 9:19 AM
Atul [Inactive]
0
Thanks, i saw math.ceil on other discussions about this Halloween code but i am trying to solve this way. It should work but isn't working. :)
15th Dec 2021, 9:24 AM
isaac