0

Is my code correct?

I completed the code coach after many tries but i am still confused about my code that whether i have written it in correct way or it is just working. Question: You go trick or treating with a friend and all but three of the houses that you visit are giving out candy. One house that you visit is giving out toothbrushes and two houses are giving out dollar bills. Task Given the input of the total number of houses that you visited, what is the percentage chance that one random item pulled from your bag is a dollar bill? Input Format An integer (>=3) representing the total number of houses that you visited. Output Format A percentage value rounded up to the nearest whole number. Sample Input 4 Sample Output 50 https://code.sololearn.com/cf58xKqth12q/?ref=app

21st Jan 2023, 7:19 PM
Ayush Singh
Ayush Singh - avatar
1 Resposta
+ 4
Yes, your result is correct. According to the task, you always get 2 dollars, regardless of the houses visited. So the chance of getting a dollar at any house is: 2 / houses * 100 percent You also did correctly to use a double , and Math.ceil for rounding up, and finally converting back to int.
21st Jan 2023, 7:40 PM
Tibor Santa
Tibor Santa - avatar