Halloween Coad Coach Not Working! | Sololearn: Learn to code for FREE!
¡Nuevo curso! ¡Todo programador debería aprender IA Generativa!
Prueba una lección gratuita
+ 1

Halloween Coad Coach Not Working!

I have been trying to solve the Halloween House Code Coach, I've tested many answers I made up and this one seemed to work in VS 2022 #include <iostream> using namespace std; int main(){ int houses; int part; int percent; cin >> houses; part = 100 / houses; percent = part * 2; if (part % 2 == 1) { percent++; } cout << percent << endl; } Why isn't it working past the first two???

1st Jul 2023, 10:46 PM
Illia Vo
Illia Vo - avatar
4 Respuestas
+ 3
Illia Vo I think the the calculations lose critical decimal values by doing everything with integers. Also, the code's technique for rounding up to the nearest percentage is flawed. The math library supplies the ceil() function for rounding up.
2nd Jul 2023, 2:14 AM
Brian
Brian - avatar
+ 2
Illia Vo, I don't have a strong recommendation for you. This site came up when I searched just now: https://cplusplus.com/reference/cmath/
2nd Jul 2023, 8:13 PM
Brian
Brian - avatar
+ 1
Hint: 200 divided by number of houses, then round it to the nearest integer, this should be working.
2nd Jul 2023, 2:27 AM
Dragon RB
Dragon RB - avatar
0
Brian I have browsed the internet and couldn’t find a good guide on cmath lib can you recommend any? Thx you were of big help @Brian
2nd Jul 2023, 6:11 PM
Illia Vo
Illia Vo - avatar