Code coatch test cases green, but fail.(SOLVED) | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

Code coatch test cases green, but fail.(SOLVED)

I have done the Halloween candy code cotch. The test cases visible to me are green, and the expected output is correct. Still i'm told to try again. How can this be? #include <iostream> using namespace std; int main() { int houses; cin>>houses; //your code goes here float average; average = 2.0/houses; cout << int((average * 100 + 0.5)); return 0; }

20th Sep 2021, 7:03 AM
Magne
Magne - avatar
5 Answers
+ 6
Maybe hidden test cases don't match with your solution. Btw, can we see your code?
20th Sep 2021, 7:37 AM
Simba
Simba - avatar
+ 6
Output should be rounded up to the nearest integer. Try this #include <iostream> #include <cmath> using namespace std; int main() { int houses; cin>>houses; //your code goes here float average; average = 2.0/houses; cout << ceil(average * 100 ); return 0; }
20th Sep 2021, 11:37 AM
Simba
Simba - avatar
+ 2
Hi Magne As Simba has suggested, we can't really help you unless we see your code. Please copy & paste into this post so we may review
20th Sep 2021, 8:42 AM
Rik Wittkopp
Rik Wittkopp - avatar
+ 2
average = 2.0/houses; Change this line as: average = 2.0/(float)houses; Or: add #include <math.h> and change the last line as: cout<<ceil(average*100); I hope, it helps. Happy coding!
20th Sep 2021, 9:45 AM
mesarthim
mesarthim - avatar
+ 2
That worked. Surprised it was so specific about how to solve it. My initial sollution should work, but then again, i can not see the testcases that failed.
20th Sep 2021, 12:11 PM
Magne
Magne - avatar