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.


Results 1 to 15 of 15

Thread: Ever Built a BMI calculator?

  1. #1

    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. #2
    actionAction's Avatar
    1,142
    posts
    humanBeing._beard=true;
    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. #3
    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. #4
    actionAction's Avatar
    1,142
    posts
    humanBeing._beard=true;
    No problem! FYI, you are in the wrong forum...but I went ahead and whipped this up for ya:
    Code:
    <html>
    <head>
    <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);
    }
    
    window.onload = function()
    {
        weight = doc("weight");
        feet = doc("feet");
        inches = doc("inches");
        BMI = doc("BMI");
        advice = doc("advice");
    }
    
    function getBMI()
    {
        weight = parseInt(weight.value);
        height = parseInt(feet.value)*12 + parseInt(inches.value);
        
        if(weight == "" || isNaN(weight) || height == "" || isNaN(height))
        {
            alert("Please enter numeric values for height and weight");
            return;
        }
        else
        {
            massIndex = 703 * (weight / Math.pow(height, 2));
            BMI.value = massIndex.toFixed(3);
            
            if(massIndex < 18.5)
            {
                advice.innerHTML = "<p>You are underweight, <span style='color:#ff0000;'>eat a freakin burger already</span>!</p>";
            }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>
    </head>
    <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>
    <td>BMI: </td><td><input type="text" id="BMI" readonly=readonly value="" /></td></tr>
    <tr><td colspan=2><input type="button" onclick="javascript:getBMI();" value="Check My BMI" /><input type="reset" /></td></tr>
    </table>
    <div id="advice"></div>
    </form>
    Last edited by actionAction; March 11th, 2008 at 09:09 PM.

  5. #5
    Rofl actionAction. Make me a monkey!
    If you notice this notice you will notice that this notice is not worth noticing.

    "Are you doing anything tonight? If not, how about me?"

    Opera Sucks! - FIX IT
    Oliver Zheng

  6. #6
    actionAction's Avatar
    1,142
    posts
    humanBeing._beard=true;
    i'm at work! what else am i gonna do...work?

  7. #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.
    MS Paint FTW!


  8. #8
    Quote Originally Posted by actionAction View Post
    No problem! FYI, you are in the wrong forum...but I went ahead and whipped this up for ya:
    Code:
    <html>
    <head>
    <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);
    }
    
    window.onload = function()
    {
        weight = doc("weight");
        feet = doc("feet");
        inches = doc("inches");
        BMI = doc("BMI");
        advice = doc("advice");
    }
    
    function getBMI()
    {
        weight = parseInt(weight.value);
        height = parseInt(feet.value)*12 + parseInt(inches.value);
        
        if(weight == "" || isNaN(weight) || height == "" || isNaN(height))
        {
            alert("Please enter numeric values for height and weight");
            return;
        }
        else
        {
            massIndex = 703 * (weight / Math.pow(height, 2));
            BMI.value = massIndex.toFixed(3);
            
            if(massIndex < 18.5)
            {
                advice.innerHTML = "<p>You are underweight, <span style='color:#ff0000;'>eat a freakin burger already</span>!</p>";
            }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>
    </head>
    <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>
    <td>BMI: </td><td><input type="text" id="BMI" readonly=readonly value="" /></td></tr>
    <tr><td colspan=2><input type="button" onclick="javascript:getBMI();" value="Check My BMI" /><input type="reset" /></td></tr>
    </table>
    <div id="advice"></div>
    </form>

    Thank you!!!

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


  10. #10
    actionAction's Avatar
    1,142
    posts
    humanBeing._beard=true;

  11. #11
    Quote Originally Posted by Charleh View Post
    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.

  12. #12
    actionAction's Avatar
    1,142
    posts
    humanBeing._beard=true;
    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)

  13. #13
    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!

  14. #14
    Quote Originally Posted by Charleh View Post
    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.
    2006-11 GlosRFC - Searching 8,168,684,336 brain cells

  15. #15
    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.
    MS Paint FTW!


Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

Home About kirupa.com Meet the Moderators Advertise

 Link to Us

 Credits

Copyright 1999 - 2012