+ 2
[CodeCoach] How is my solution to Halloween Candy Wrong? (C++)
I was trying to solve some "easy" code coach problems in this app, ok everything was cool until i tried to solve "Halloween Candy" I used C++ (because that's my primary language) and I thought my solution was good enough but when I ran the code i solved case 1 & 2 but the other cases were wrong. Oh, and all the cases i got wrong were LOCKED, so i couldn't see the problem. Can anyone help me and tell me the problem in my code? : #include <iostream> #include <cmath> using namespace std; int main() { double visited; cin >> visited; cout << round(100*2/visited); return 0; }
1 Answer
+ 7
Pay attention to the detail of the task.
"rounded up to the nearest whole number"
Use the ceil function to round up, instead of round to the closest integer.