LBS_PER_KG = 2.2
IN_PER_FT = 12
CM_PER_IN = 2.54
# bmi : float, int, float -> float
# Calculate somebody's bmi, given their weight (in pounds)
# and their height as a number of (whole) feet and also the additional inches.
#
def bmi( weightLbs, wholeFt, extraIn ):
weightKg = weightLbs / LBS_PER_KG
heightIn = float(wholeFeet)*IN_PER_FT + extraInches
heightCm = heightIn * CM_PER_IN
heightM = heightCm/100
return weightKg / pow(heightM,2)
|
|
double LBS_PER_KG = 2.2;
double IN_PER_FT = 12;
double CM_PER_IN = 2.54;
double bmi( double weightLbs, int wholeFt, double extraIn ) {
double weightKg;
double heightIn;
double heightCm;
double heightM;
weightKg = weightLbs / LBS_PER_KG;
heightIn = float(wholeFeet)*IN_PER_FT + extraInches;
heightCm = heightIn * CM_PER_IN;
heightM = heightCm/100;
return weightKg / Math.pow(heightM,2);
}
|
(Actually this isn't quite correct, since technically the word “static” should
be in front of the three named-constants and the function bmi.)
|