+ 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.
3 Antworten
+ 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
+ 1
I havent thought of that. Thanks for pointing that out!
0
I don’t know