Im creating a bmi caculator and im using the height and weight formula. I keep getting an erorr that says nan obese at the very end and i dont know what i'm missing or what i need to edit. Any help would be appreciated.
//BMI = (703 * weightInPounds) / heightInInches^2 is the formula
import java.util.Scanner;
public class Bmi_Calc {
public static void main(String[] args) {
// TODO Auto-generated method st
Scanner input = new Scanner(System.in);
//double weight;
double weightInPounds;
int feet;
int inches;
//int weightInPounds;
int heightInInches;
double height;
System.out.print("Enter Weight in pounds: ");
double weight = input.nextDouble();
System.out.println("Enter height (ft.): ");
feet = input.nextInt();
System.out.println("Enter height (in.): ");
inches = input.nextInt();
weightInPounds = 0;
heightInInches = 0;
double bmi = (703 * weightInPounds) / Math.pow(heightInInches, 2.0);
double heightMeters = ((feet * 12) + inches) * .0254;
System.out.println("Your BMI is: " + bmi);
if (bmi < 18.5) {
System.out.println("Underweight.");
}
if ((bmi >= 18.5) && (bmi < 24.9)) {
System.out.println("Normal weight");
}
if ((bmi >= 25) && (bmi < 29.9)) {
System.out.println("Overwight");
}
else {
System.out.println("Obese");
}
input.close();
}
}
Aucun commentaire:
Enregistrer un commentaire