I created a java program to calculate a persons BMI, but we have to convert the weight from pounds to kilos and height from inches to meters using the numbers in my program, but it just doesnt worl the way its suppose to can some PLEASE help me figure it out.

//Body Mass Index.java
//Davina Moore
//Due: September 18, 2008
//This java program is designed to compute your Body Mass Index

import java.util.Scanner;
import java.text.DecimalFormat;

public class Body_Mass_Index
{

public static void main(String args[ ])
{
double pound = .0453592;
double inches = .0254;

double weight = pound *.0453592;
double height = inches *.0254;
double BMI = weight/(height*height);

Scanner scan = new Scanner(System.in);

weight = scan.nextDouble();

height = scan.nextDouble();

//rounds the answer to 2 decimal places
DecimalFormat fmt = new DecimalFormat("0.##");

System.out.println("Your Body Mass Index is: " + fmt.format(BMI));

}

}

Hello,

try this :

``````double pound = .0453592;
double inches = .0254;

Scanner scan = new Scanner(System.in);

double weight = scan.nextDouble();

double height = scan.nextDouble();

weight *= pound;
height *= inches;
double BMI = weight/(height*height);

//rounds the answer to 2 decimal places
DecimalFormat fmt = new DecimalFormat("0.##");

System.out.println("Your Body Mass Index is: " + fmt.format(BMI));``````

Regards,
Puneet

i still dont get the right answer
why you make the changes you did

i still dont get the right answer
why you make the changes you did

Hello again,

There must be some calculation problem then because program is working and giving an output too. I dont know about BMI formula so i cant tell you surely.

``````weight *= pound; // Equals to weight = weight * pound and pound = .0453592;
height *= inches; // Equals to height = height * inches and inches = .0254;
double BMI = weight/(height*height); // Formula for BMI Calculation.``````

We have initialized pound and inches variables at top before everything. That is good and well.

but you did all calculation before input values (weight & height) from console. That is wrong.

So i moved calculation part down after input from console.

Regards,
PuneetK

What puneetkay is trying to say is that you must first read the input from the console and then do the calculations, not the other way around

What puneetkay is trying to say is that you must first read the input from the console and then do the calculations, not the other way around

No, Im trying to help him with the simplest way as you can see he is newbie.

Even, im a newbie. im just sharing my knowledge here :) If im wrong, you seniors are here to help us.

Regards,
PuneetK

No, Im trying to help him with the simplest way as you can see he is newbie.

Even, im a newbie. im just sharing my knowledge here :) If im wrong, you seniors are here to help us.

Regards,
PuneetK

No, you fixed some of his code and then provided no explanation of what you did or why, which does nothing to promote learning. javaAddict was merely trying to provide the explanation that you did not bother to give.

thanks for everyone's help and input.....
my program works fine.

Just a side note i'm not a newbie its just im new to this site, and i had a very bad java teacher in the past so now i have to retake java to get into grad school....

fyi, im a her not a he...
lol

thanks for everyone's help and input.....
my program works fine.

Just a side note i'm not a newbie its just im new to this site, and i had a very bad java teacher in the past so now i have to retake java to get into grad school....

fyi, im a her not a he...
lol

Regards,

I created a java program to calculate a persons BMI, but we have to convert the weight from pounds to kilos and height from inches to meters using the numbers in my program, but it just doesnt worl the way its suppose to can some PLEASE help me figure it out.

``````//Body Mass Index.java
//Davina Moore
//Due: September 18, 2008
//This java program is designed to compute your Body Mass Index

import java.util.Scanner;

public class CalculateBMI {

public static void main(String[] args) {
double weight;
double foot=0.3048;
Scanner scan = new Scanner(System.in);
weight = scan.nextDouble();
double height = scan.nextDouble();
height= height*foot;
double BMI = weight/(height*height);
System.out.println("Your Body Mass Index is: " +BMI);

}
``````
commented: Well over a year late, no code tags, nothing new to add anyway -4

No, you've just dragged up a year-old question that has already beed resolved and posted some code with no explanation. Do you think that is helpful?

well, the original was also wrong.
The politically correct solution is simple:

``System.out.println("you're morbidly obese");``

is the correct response to any data entered into the application.

You never converted weight in pounds to kilograms' which is why the program gave the wrong answer

this is how i changes it:

``````import java.util.Scanner;

public class CalculateBMI
{

public static void main(String[] args)
{
double weight;
Scanner scan = new Scanner(System.in);
weight = scan.nextDouble();
double weightkg = weight/2.2;