Halloween Candy | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
25th Apr 2020, 4:56 PM
Vincent Petrocelli
Vincent Petrocelli - avatar
6 Answers
+ 1
Vincent Petrocelli 6 houses: 2 / 6 = 0.33 * 100 = 33.33 .33 < .5 -> Round rounds down to 33.00 Ceiling -> 34.00
26th Apr 2020, 11:52 AM
Denise Roßberg
Denise Roßberg - avatar
+ 3
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace SoloLearn { class Program { static void Main(string[] args) { int houses; houses = Convert.ToInt32(Console.ReadLine()); //your code goes here int result = (int)(Math.Ceiling((double)2/houses*100)); Console.WriteLine(result); } } }
17th Dec 2021, 4:59 PM
Alain Sauve
0
You need to round up. You should use Math.Ceil() and then convert it to int.
25th Apr 2020, 6:23 PM
Denise Roßberg
Denise Roßberg - avatar
0
Sorry the correct method name is Math.Ceiling() Ceiling rounds always up.
25th Apr 2020, 6:41 PM
Denise Roßberg
Denise Roßberg - avatar
0
Thx, but kinda curious, what input would make the code not round up?
26th Apr 2020, 6:36 AM
Vincent Petrocelli
Vincent Petrocelli - avatar
- 1
I had to use Math.Round because Math.Ceil didnt exist but same result unfortunatly
25th Apr 2020, 6:35 PM
Vincent Petrocelli
Vincent Petrocelli - avatar