The forums have permanently moved to forum.kirupa.com. This forum will be kept around in read-only mode for archival purposes. To learn how to continue using your existing account on the new forums, check out this thread.

# Thread: Ever Built a BMI calculator?

1. 42
posts
Registered User

## Ever Built a BMI calculator?

I'm looking to make a BMI calculator, but I'm having trouble figuring out how. I'm a designer and do not know much scripting.

Has anyone made one of these before?

Thanks!

2. Sounds like a school project...

You didn't say what language you need it programmed in, or where you are in the world, so I will insert C++ and America (how American of me!)
Code:
```#include<iostream>
#include<cmath>
using namespace std;

int main()
{
int heightInInches,
weightInPounds;

float BMI;

cout << "Enter your height in inches: ";
cin >> heightInInches;
cout << "Enter your weight in pounds: ";
cin >> weightInPounds;

BMI = 703 * (weightInPounds/ pow(heightInInches, 2));
cout << "Your BMI is " << BMI << "\n";

return 0;
}```

3. 42
posts
Registered User
Thanks so much! Sorry for not being very descriptive.

I am in America and if possible I'd like it in javaScript. I work for a hospital and we I'm trying to build something for people to use on our site.

4. No problem! FYI, you are in the wrong forum...but I went ahead and whipped this up for ya:
Code:
```<html>
<title>BMI Calculator</title>
<script type="text/javascript">
var weight;
var height;
var feet;
var inches;
var BMI;

var sURL = unescape(window.location.pathname);

function doc( id )
{
return document.getElementById(id);
}

{
weight = doc("weight");
feet = doc("feet");
inches = doc("inches");
BMI = doc("BMI");
}

function getBMI()
{
weight = parseInt(weight.value);
height = parseInt(feet.value)*12 + parseInt(inches.value);

if(weight == "" || isNaN(weight) || height == "" || isNaN(height))
{
return;
}
else
{
massIndex = 703 * (weight / Math.pow(height, 2));
BMI.value = massIndex.toFixed(3);

if(massIndex < 18.5)
{
}else if(massIndex >=18.5 && massIndex < 29.9)
{
advice.innerHTML = "<p>You are sooo normal, good job</p>";
}else if(massIndex > 29.9)
{
advice.innerHTML = "<p>Put down the Twinkies and step away from McDonalds</p>";
}
}
}

function refresh()
{
window.location.href = sURL;
}
</script>
<body>
<form method="post" action="return false;" onreset="javascript:refresh();">
<table>
<tr>
<td>Height:</td><td><input type="text" id="feet" size=5 maxlength=2 onfocus="" value="" /> ft.<input type="text" size=5 id="inches" maxlength=2 value="" /> in.</td></tr>
<td>Weight:</td><td><input type="text" id="weight" size=7 maxlength=3 value="" /> lbs.</td></tr>
<tr><td colspan=2><input type="button" onclick="javascript:getBMI();" value="Check My BMI" /><input type="reset" /></td></tr>
</table>
</form>```
Last edited by actionAction; March 11th, 2008 at 09:09 PM.

5. Rofl actionAction. Make me a monkey!

6. i'm at work! what else am i gonna do...work?

7. 1,627
posts
hugeExplosions = true;
BMI is a load of rubbish. It just tells you how heavy you are in proportion to your height - how does that tell you anything useful? Bodybuilders and athletes BMIs are off the charts - are they not their ideal weight? I'd say they are 10 times more healthy than a skinny guy with a perfect BMI.

Tell you a better indication of weight... the mirror

If you can't see muscle definition anywhere, even in your forearms or upper arms, you are fat. If your knuckles dimple when you stretch your hand out then you are really fat.

If you have muscles and striations poking out everywhere and you can see your ribs through your translucent malnourished skin then you are thin.

Anything in between is about right.

8. 42
posts
Registered User
Originally Posted by actionAction
No problem! FYI, you are in the wrong forum...but I went ahead and whipped this up for ya:
Code:
```<html>
<title>BMI Calculator</title>
<script type="text/javascript">
var weight;
var height;
var feet;
var inches;
var BMI;

var sURL = unescape(window.location.pathname);

function doc( id )
{
return document.getElementById(id);
}

{
weight = doc("weight");
feet = doc("feet");
inches = doc("inches");
BMI = doc("BMI");
}

function getBMI()
{
weight = parseInt(weight.value);
height = parseInt(feet.value)*12 + parseInt(inches.value);

if(weight == "" || isNaN(weight) || height == "" || isNaN(height))
{
return;
}
else
{
massIndex = 703 * (weight / Math.pow(height, 2));
BMI.value = massIndex.toFixed(3);

if(massIndex < 18.5)
{
}else if(massIndex >=18.5 && massIndex < 29.9)
{
advice.innerHTML = "<p>You are sooo normal, good job</p>";
}else if(massIndex > 29.9)
{
advice.innerHTML = "<p>Put down the Twinkies and step away from McDonalds</p>";
}
}
}

function refresh()
{
window.location.href = sURL;
}
</script>
<body>
<form method="post" action="return false;" onreset="javascript:refresh();">
<table>
<tr>
<td>Height:</td><td><input type="text" id="feet" size=5 maxlength=2 onfocus="" value="" /> ft.<input type="text" size=5 id="inches" maxlength=2 value="" /> in.</td></tr>
<td>Weight:</td><td><input type="text" id="weight" size=7 maxlength=3 value="" /> lbs.</td></tr>
<tr><td colspan=2><input type="button" onclick="javascript:getBMI();" value="Check My BMI" /><input type="reset" /></td></tr>
</table>
</form>```

Thank you!!!

9. 1,627
posts
hugeExplosions = true;
Sorry my post wasn't helpful just a random rant

10. 42
posts
Registered User
Originally Posted by Charleh
Sorry my post wasn't helpful just a random rant

hahaha, not a problem. I'll have to dress it up a bit and I'll be on my way. Hopefully I'll get to it today or tomorrow.

11. A link would be nice, if'n ya please. Just to see it in action(Action).

@Charleh: "The fingers you have used to dial are too fat, to obtain a special dialing wand, please mash the keypad now" (I thought of the Simpsons when I read your post)

12. 42
posts
Registered User
hahahah

I'll get you a link. Though the final page may not be done for a few weeks as it's part of an upcoming ad campaign. Regardless, I'll get you a link when I include it!

Thanks again!

13. Originally Posted by Charleh
Bodybuilders and athletes BMIs are off the charts - are they not their ideal weight? I'd say they are 10 times more healthy than a skinny guy with a perfect BMI.
Explain that to all the bodybuilders and athletes that have expired prematurely because of steriod abuse and coronary disease. And yet, strangely enough, the fittest soldiers tend to be thin and wiry; the fittest athletes tend to be skinny Ethopians; and the fittest actionscripters exist on a diet of pizza and beer.

14. 1,627
posts
hugeExplosions = true;
Nope, steroid using bodybuilders expire prematurely - the ones that want to be freaky big or the competition goers. Those that build naturally don't tend to be that big but they don't see the same problems.

I don't agree with the second part - the strongest soldiers tend to be the big guys...the fittest? Well you can't really argue about who is the fittest when there's no even scale - a big guy has a lot more muscle to move about and most likely a more dense bone structure due to the bone restructuring from the stress of weights and exertion. The skinny guy has less weight to move around so he might be able to run further or faster for longer but only because his heart doesn't have to work as hard.

Ethiopians can run really far yeah, but stick em in an olympic wrestling tournament and they won't even be able to beat the lowest seed. No sport at that level is easy sport - apart from darts and snooker

You can't place a measure on fitness, but you can on fatness, and BMI does neither.