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

Page 1 of 1

## 4 Replies - 564 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=e8a10fc91f3d76fe297badd9c505dca6&md5check=' + ipb.vars['secure_hash'], cur_rating: 0, rated: 0, allow_rate: 0, multi_rate: 1, show_rate_text: true } ); //]]>

### #1 amen69

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;

scanf("%f",&kg);

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: 4912
• Posts: 15,338
• 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: 6237
• Posts: 24,002
• 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

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;

scanf("%f",&kg);

scanf("%f",&cm);

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

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

return 0;
}

```