+ 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???
4 odpowiedzi
+ 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.
+ 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/
+ 1
Hint: 200 divided by number of houses, then round it to the nearest integer, this should be working.
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