+ 2
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);
18 Respuestas
+ 3
Татьяна // 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?
+ 2
~ 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);
+ 2
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!
+ 2
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 👍
+ 2
You are welcome ☺️
+ 2
Татьяна // 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()));
+ 2
Татьяна // Tatiana it's a general mathematical thing.
2*100/houses
and
2/(houses) * 100
Are same.
+ 1
Thank you so much! Ceiling worked. I don't understand the difference, but eventually i will.
+ 1
~ 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😂😂
+ 1
houses = int(input())
#your code goes here
import math
print(math.ceil(2/(houses)*100))
+ 1
KUMAR SHANU hmmm, I might be wrong here, but isn't it supposed to be 2*100/houses?
+ 1
Татьяна // Tatiana
Ohh ya
I forgot
import math
print(math.ceil(200/int(input())))
+ 1
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.
+ 1
Alexander Thiem well, the whole thing forced me to learn many unexpected things 🙈
0
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?