+ 1

my wrong "halloween candy" solution

Can someone tell me how do You understand this puzzle, and what is wrong in my code. I wasn't able to understand the given problem in this puzzle. I managed to clear it by messing around with values and Switch. #include <iostream> #include <cmath> using namespace std; int main() { int house; cin>>house; float houses; houses=house; int a,b,c; //your code goes here int bills=2; int tooth=1; float candy; /* if (houses>3){ candy=houses-3; } else{ candy=0; } */ switch (house) { case 51 ... 500: candy=4; cout<<candy; break; case 2 ... 50: candy=2/houses*100; candy=round(candy); cout<<candy<<endl; break; /* case 2: candy=50; cout<<candy; break; case 1: candy=0; cout<<candy; break; */ default: candy=1; cout<<candy; break; } //4=1candy,2bills,1tooth //5=2candy,2bills,1tooth return 0; }

3rd Sep 2020, 3:50 PM
Kamil Koćwin
5 odpowiedzi
0
Read your output format, read it carefully 👍👍
3rd Sep 2020, 4:05 PM
Steven M
Steven M - avatar
+ 1
/* I believe you are over thinking. What I do is copy the problem into my code as a comment. This way I don't have to switch back and forth. Also, read the problem carefully and only solve for what they're asking. While your solution may work, you have to remember this is an "easy" challenge, so it should require an easy solution. */ #include <iostream> #include <cmath> /* Task Given the input of the total number of houses that you visited, what is the percentage chance that one random item pulled from your bag is a dollar bill? Input Format An integer (>=3) representing the total number of houses that you visited. Output Format A percentage value rounded up to the nearest whole number. Sample Input 4 Sample Output 50 */ using namespace std; int main() { float houses; cin>>houses; //your code goes here cout<<ceil(200/houses); return 0; }
3rd Sep 2020, 3:59 PM
Steven M
Steven M - avatar
0
but why You used "ceil" and not "round"? Is it possible to make it work with round()?
3rd Sep 2020, 4:04 PM
Kamil Koćwin
0
I mean, my solution will pass tests, but it's still wrong xD
3rd Sep 2020, 4:06 PM
Kamil Koćwin
0
I get now why I was so confused. "Rounded up to the nearest whole number" For 3.2 nearest for me is 3, but for this puzzle You need to round up to 4, they trying to tell You (badly) to use ceil()
4th Sep 2020, 6:42 AM
Kamil Koćwin