# i get 0 for my bmi calculator answer can you help me whats wrong with?

Page 1 of 1

## 4 Replies - 476 Views - Last Post: 08 October 2011 - 08:22 AMRate Topic: //<![CDATA[ rating = new ipb.rating( 'topic_rate_', { url: 'http://www.dreamincode.net/forums/index.php?app=forums&module=ajax&section=topics&do=rateTopic&t=250384&amp;s=2a5d8a9258375809950f186beff32088&md5check=' + ipb.vars['secure_hash'], cur_rating: 0, rated: 0, allow_rate: 0, multi_rate: 1, show_rate_text: true } ); //]]>

### #1 amen69

• New D.I.C Head

Reputation: 0
• Posts: 1
• Joined: 08-October 11

# i get 0 for my bmi calculator answer can you help me whats wrong with?

Posted 08 October 2011 - 08:08 AM

```#include <stdio.h>

int main(void)
{
float kg;
float cm;
int sum;

printf("Enter your weight in kg\n");
scanf("%f",&kg);

printf("Enter your height in cm\n");
scanf("%f",&cm);

sum = (kg)/(cm*cm);

printf("Sum is %d\n",sum);

return 0;
}
```

MOD EDIT: Added code tags. When posting code...USE CODE TAGS!!!

This post has been edited by JackOfAllTrades: 08 October 2011 - 08:09 AM

Is This A Good Question/Topic? 0

## Replies To: i get 0 for my bmi calculator answer can you help me whats wrong with?

### #2 jimblumberg

Reputation: 4565
• Posts: 14,417
• Joined: 25-December 09

## Re: i get 0 for my bmi calculator answer can you help me whats wrong with?

Posted 08 October 2011 - 08:14 AM

What did you input into your program?

If you want sum to show any fractional amounts you will need to make sum a floating point number.

Jim

### #3 Karel-Lodewijk

Reputation: 454
• Posts: 864
• Joined: 17-March 11

## Re: i get 0 for my bmi calculator answer can you help me whats wrong with?

Posted 08 October 2011 - 08:15 AM

2 problems.

1) BMI is kg/m^2, not kg/cm^2.

2) Because of the wrong formula you will always get a bmi < 1 which when stored in an int will be rounded down, you probably want sum to be a float as well.

• Saucy!

Reputation: 6180
• Posts: 23,882
• Joined: 23-August 08

## Re: i get 0 for my bmi calculator answer can you help me whats wrong with?

Posted 08 October 2011 - 08:15 AM

Your formula for BMI calculation is wrong.

### #5 FatalTouch

• New D.I.C Head

Reputation: 6
• Posts: 30
• Joined: 07-October 11

## Re: i get 0 for my bmi calculator answer can you help me whats wrong with?

Posted 08 October 2011 - 08:22 AM

This is your typical BMI program...

```	#include <stdio.h>

int main()
{
float kg;
float cm;
float sum;

printf("Enter your weight in kg\n");
scanf("%f",&kg);

printf("Enter your height in cm\n");
scanf("%f",&cm);

sum = (kg)/((cm*cm)/10000);

printf("BMI is %f\n",sum);

return 0;
}

```