Instead of having to do this on paper and a calculator I decided to make a sweet Perl script to do this for me. Any comments are welcomed since I don't claim to be a Perl expert by any means. Enjoy!
#!/usr/bin/perl use strict; use warnings; use 5.010; # BMI Calculator For Men # Created by: Jamie Newton # 12-11-10 Formula Cited Sources # The Body Sculpting Bible for Men, Hugo Rivera & James Villepique # Introduction ------------------------------------------------------- +------------- say "BMI CALCULATOR FOR MEN\n\nHello, this tool will calculate your to +tal fat percentage."; # Declare Variables to be used in Script my($current_weight); my($waist_girth); my($BodyShape); # Collect User's Weight ---------------------------------------------- +------------- do { say "Please enter your current weight >"; chomp($current_weight = <STDIN>); } until ($current_weight =~ /^[0-9]+$/); # Collect User's Waist Size ------------------------------------------ +------------- do { say "Please enter your waist girth (measured at the umbilicus) + >"; chomp($waist_girth = <STDIN>); } until ($waist_girth =~ /^-{0,1}\d*\.{0,1}\d+$/); # Get Lean Body Weight (as if you had no fat at all) ----------------- +-------------- my $Result1 = ($current_weight * 1.082) + 94.42; my $Result2 = $Result1 - ($waist_girth * 4.15); # Round to 2 decimal Places ------------------------------------------ +-------------- my $BodyFatPercentage = sprintf "%.2f"; # Find Out The Total Body Fat Percentage ----------------------------- +-------------- chomp($BodyFatPercentage = (($current_weight-$Result2) * 100) / $curre +nt_weight); # Determine if the User is Underweight, Healthy, Overweight, or Obese if ($BodyFatPercentage < 18) { $BodyShape = "Underweight"; } elsif ($BodyFatPercentage > 17 && $BodyFatPercentage < 25) { $BodyShape = "Healthy"; } elsif ($BodyFatPercentage > 24 && $BodyFatPercentage < 30) { $BodyShape = "Overweight"; } elsif ($BodyFatPercentage >= 30) { $BodyShape = "Obese"; } #Display BF % to User print "\nYour Total Body Fat % is "; print sprintf("%.2f", $BodyFatPercentage); print "%\n\n"; print "This indicates that you are $BodyShape."; print "\n\n"; print "Extra: Your weight without any fat = $Result2"; print "\n\n\n\n\n";
The early bird gets the worm but the second mouse gets the cheese.
pretendeavor
pretendeavor
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Body Mass Index Calculator
by toolic (Bishop) on Jan 29, 2011 at 03:05 UTC | |
by naildownx (Beadle) on Jan 29, 2011 at 04:23 UTC | |
Re: Body Mass Index Calculator
by GrandFather (Saint) on Jan 29, 2011 at 04:51 UTC | |
by naildownx (Beadle) on Jan 29, 2011 at 21:56 UTC | |
Re: Body Mass Index Calculator
by wazoox (Prior) on Jan 30, 2011 at 21:25 UTC | |
by naildownx (Beadle) on Feb 06, 2011 at 04:57 UTC |
Back to
Cool Uses for Perl