0

How can I make my program's output more accurate? (Java)

Hello fellow programmers, I've been having some accuracy issues with a program I've been working on and I'd appreciate your help. Consider the following code: https://code.sololearn.com/c0fmPgw38g1N/#java As you can see from the code, this project is a BMI calculator. I already tried to solve problems with accuracy by removing doubles and using the BigDecimal class, but I still end up with imperfect results. For example, if you go to the first hit on Google for BMI calculators (https://www.nhlbi.nih.gov/health/educational/lose_wt/BMI/bmicalc.htm) and input your height and weight as, say, 6' 1" and 158 pounds, you get a BMI of 20.8. Putting the metric equivalents of those values (185.42 cm and 71.67 kg) into the metric version of the calculator gives you the same result. However, using my calculator results in a BMI of 21.0 (Imperial) and 20.9 (Metric). A similar issue presents itself with different height and weight combinations. While my values are pretty close to the proper result, I would like them to have a lot less margin of error. I would appreciate anyone being willing to look over my code and find if there are any hidden issues preventing me from getting accurate results. Thanks in advance. Peter

15th Feb 2017, 10:02 PM
Peter Hubbard
Peter Hubbard - avatar
1 Answer
0
I didn't review your implementation, however I do notice your calculations are off by a lot more than decimals. Metric input 180cm 75kg output from your program = 19.0 output via website https://www.nhlbi.nih.gov/health/educational/lose_wt/BMI/bmi-m.htm output from website = 23.1 your calculations are way off.
16th Feb 2017, 12:08 AM
Michael W
Michael W - avatar