+ 29

Does anyone understand the problem Halloween Candy ?

18th Dec 2019, 7:28 AM
Hima
Hima - avatar
60 odpowiedzi
+ 32
Am trying with C++ The main formula i made is round(200/houses) I passed 2 tests but failed next 3. Whats the matter?
21st Dec 2019, 7:25 PM
Sarthak Gupta
Sarthak Gupta - avatar
+ 22
Explanation : The problem states that all the houses you and your friends visit gives candy except 3 houses, among these 3 houses, 1 house give toothbrushes and 2 houses gives dollar. Also the output must "round up" not "round figure or approximate", which means if 20.1 is the output then the "round up" is 21 not 20. Example explanation: If you and your friends visit 10 houses then 7 houses gives candy, 1 house gives toothbrushes and remaining 2 houses gives dollar. """ Code by "Shivaneeth P" Python code """ import math houses = int(input()) #probability of dollar per one house probability_dollar=2.0/houses #percentage of dollar for all houses percentage_dollar = probability_dollar * 100.0 #rounding up value print(math.ceil(percentage_dollar))
30th May 2020, 2:16 PM
Shivaneeth P
Shivaneeth P - avatar
+ 18
That is because if you use round there is a problem Round(2.5)=2 try with ceil 😉
18th Dec 2019, 11:08 AM
David Martínez
David Martínez - avatar
+ 12
Chances=(2 bills/total houses)*100 The problem is... how can i round that number?
18th Dec 2019, 9:45 AM
David Martínez
David Martínez - avatar
+ 8
This is my Halloween candy solution in C++... #include <iostream> #include <cmath> using namespace std; int main() { double houses, percent; cin >> houses; percent = 2 / houses; percent = ceil(percent * 100); if (percent == (int)percent ) { cout << (int)percent ; } else cout << (int)percent + 1; //your code goes here return 0; }
3rd Jan 2020, 10:39 AM
Oluwatowo Rosanwo
Oluwatowo Rosanwo - avatar
+ 6
I'm stuck there too.. failed in 3 last cases
18th Dec 2019, 11:04 AM
Aymen
+ 6
#include <stdio.h> int main() { int houses,c; scanf("%d", &houses); c=200/houses; if(200%houses==0) printf("%d",c); else printf("%d",c+1); return 0; } This works fine..
21st Apr 2020, 6:02 PM
Regnard Viven
Regnard Viven - avatar
+ 5
Coder Kitten But as each house gives one candy ! doesnt it make four candies from four houses ?
18th Dec 2019, 7:18 PM
Hima
Hima - avatar
+ 4
I am not understanding this question, can anyone explain this question briefly?
1st Jan 2020, 12:44 PM
Nikhil Maske
+ 4
My solution : #include<iostream> using namespace std; int main () { int n; cin>>n; int d = 200/n; cout<< (200%n?d+1:d); return 0; }
19th Feb 2020, 2:20 PM
Nandini Chaudhary
Nandini Chaudhary - avatar
+ 3
Coder Kitten thanks 200.0 worked. Now I got that 200 and 200.0 are different David Martínez #include <cmath> float x = round(200.0/houses); That's how I rounded it and it worked.
21st Dec 2019, 7:41 PM
Sarthak Gupta
Sarthak Gupta - avatar
+ 2
Sarthak Gupta how do you round the number?
21st Dec 2019, 7:27 PM
David Martínez
David Martínez - avatar
+ 2
I failed in three last cases. Somebody has the spec that those cases? I am not a pro member. Please send me a email to: *redacted* Have a nice day!
29th Dec 2019, 8:07 AM
Luis Vargas Guzman
Luis Vargas Guzman - avatar
+ 2
undefinedGalaxy There's no need to do that. Updated code! #include <iostream> #include <cmath> using namespace std; int main() { double houses, percent; cin >> houses; percent = 2 / houses; percent = ceil(percent * 100); /* if (percent == (int)percent ) { cout << (int)percent ; } else*/ cout << (int)percent ; //your code goes here return 0; }
2nd Feb 2020, 6:32 AM
Hima
Hima - avatar
+ 2
Can someone please explain me the question i don't get it
25th Mar 2020, 8:17 AM
Raza Alam
Raza Alam - avatar
+ 2
Hello, My code in Python below. I didn't use any special functions like round. Just compare int and float results. houses = int(input()) dolar=200.0/houses if dolar==int(dolar): print(int(dolar)) else: print(int(dolar+1))
10th May 2020, 6:59 PM
Rafał Kmieciak
Rafał Kmieciak - avatar
+ 2
I passed first two cases but left three did'nt
30th Jun 2020, 7:39 AM
Vaishnavi Ojha
Vaishnavi Ojha - avatar
+ 2
Here is in C++ #include <iostream> #include <cmath> using namespace std; int main() { int houses; cin>>houses; double percent =200; //your code goes here if(houses>=3){ percent /=houses; cout<<ceil(percent); } return 0; }
21st Apr 2021, 8:44 AM
Joe Hutchens
Joe Hutchens - avatar
+ 1
I was about to do it, but I got my head wrapped on the "army time" one. I read its description and it was a bit confusing, tho. If I happen to do the halloween one tomorrow, I'll try to share the experience.
18th Dec 2019, 9:24 AM
Fernando Pozzetti
Fernando Pozzetti - avatar
+ 1
I failed in three last cases. Somebody has the spec of those cases? I am not a pro member. I think it is because we should consider what happens if the user introduces a invalid value, for example a float, because the problem must receive a integer. I guess, I do not know xD
29th Dec 2019, 8:11 AM
Luis Vargas Guzman
Luis Vargas Guzman - avatar