--Originally published at Valeria CT
I struggled a bit with this WSQ because of the lack of precision in decimals, I tried restricting the loop conditional, but it didn’t work. What I did was I rounded the numbers (multiplying them by 100000000 first) and then dividing them by 100000000 to get the original number but with a limited amount of decimals. This way the conditional == is valid.
Here’s my code: https://github.com/valeriact/tc1017/blob/master/wsq10-2.cpp
and the resources I used:
- http://www.cplusplus.com/reference/cmath/round/
- https://stackoverflow.com/questions/14369673/c-round-double-to-3-points-decimal
- https://www.deltacollege.edu/dept/basicmath/Babylonian.htm
- Damian’s and Ken’s help
-Valeria