Halloween candy // Challenge problem //C#// hidden tests
Disclaimer: this is my first ever try in programming, so please don't be harsh. https://www.sololearn.com/coach/4?ref=app I've been trying to solve this problem in C#, and I'm obviously missing something here. But since tests 3-5 are closed up, I have no means to find out what I'm doing wrong. Can someone explain it to me? Pretty please? Here goes nothing: //this how I've tried to solve it int x = 200; //100% multiplied by 2 instances double result = ((double) x/houses); double xresult = Math.Round (result-0.1); //googled this one Console.WriteLine (xresult);
8/11/2020 10:27:08 AMТатьяна // Tatiana
18 AnswersNew Answer
Татьяна // Tatiana Ceilung rounds up to the smallest whole number that is greater or equal to the given number: 10->10 10.2->11 10.9->11 Rounding rounds to the nearest whole number: 10->10 10.2->10 10.8->11 Did you understand know?
Problem description says "rounded up to nearest integer" "Rounded up" implies ceiling, so try using Ceiling method instead of Round. Don't do result-0.1
~ swim ~ I tried the same, but as I dont know how to ceil in C# I just did something like the following. It is ugly but it works.... int houses; houses = Convert.ToInt32(Console.ReadLine()); if (houses==10) Console.WriteLine(20); else Console.WriteLine((int)((double) 200/houses)+1);
Alexander Thiem Ceiling is easy Console.WriteLine((int) Math.Ceiling((double)200/houses)); Your code can add extra one e.g houses = 4 your output ((double)200/4)+1 = 51 should be 50
Татьяна // Tatiana You are Welcome 🙂👍🙏 I am sure you will eventually understand the difference.
Pls use the search bar This question has already been asked many times Pls take care from next time And instead of copy pasting the text in your code! Copy the code link!
Namit Jain yeah, I've searched for the answer, but somehow missed it. I was able to find explanations on other programming languages, but I'm too new to this, so I couldn't connect the dots in C#. Alexander Thiem yep, that helped! Thanks, you saved me some google-time 👍
You are welcome ☺️
houses = int(input()) #your code goes here import math print(math.ceil(2/(houses)*100))
Татьяна // Tatiana Well, print(math.ceil(200/int(input())) is Python Syntax! Python is famous for beeing able to solve !every! problem in a single line if necessary. c#: Console.WriteLine((int) Math.Ceiling((double)200/Convert.ToInt32(Consile.ReadLine()));
Татьяна // Tatiana it's a general mathematical thing. 2*100/houses and 2/(houses) * 100 Are same.
Thank you so much! Ceiling worked. I don't understand the difference, but eventually i will.
~ swim ~ I do exactly know what my code does👍 I did not know how to ceil. Thanks to you I know it now. But as the only failing testcase was 10 I just did not want to google how to ceil, as my version solved the test😂😂
KUMAR SHANU hmmm, I might be wrong here, but isn't it supposed to be 2*100/houses?
Татьяна // Tatiana Ohh ya I forgot import math print(math.ceil(200/int(input())))
Namit Jain that's why I love SoloLearn ! I would've never come up with oneliner like this myself. Thank you 😎👍 Upd: tried this, can't make it work. Google says x=int (input ()) is from Python sintax.
Alexander Thiem well, the whole thing forced me to learn many unexpected things 🙈
Namit Jain it looks perfect , but aren't we need ceiling, so if there are (for example ) 3 houses, output would be 67, not 66?