+ 1

Solution for Halloween Candy problem in C#

using System; double houses; double percent; houses = Convert.ToInt32(Console.ReadLine()); percent = Convert.ToInt32((2 / houses) * 100 + 0.5); Console.WriteLine(percent); 0.5 is added so that the resulting number can be rounded up to whole number. Eg. If the resulting number is 66.3, 0.5 is added to make 66.8 which is rounded to 67. Hope this is helpful.

22nd Sep 2023, 9:36 PM
Hein Htet
Hein Htet - avatar
3 ответов
+ 3
Is there round up problem? Mention it clearly... What if result is ex: 5.9? then value added is 0.5 will result to 6.4 , leads to wrong result..! Use Math.Ceil() function on result directly without adding 0.5
23rd Sep 2023, 3:43 AM
Jayakrishna 🇮🇳
+ 1
I havent thought of that. Thanks for pointing that out!
23rd Sep 2023, 8:29 AM
Hein Htet
Hein Htet - avatar
0
I don’t know
24th Sep 2023, 4:36 PM
Ruby Clary