Help with this formula!

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
thirtyfourtwenty
Forum Newbie
Posts: 1
Joined: Tue Apr 14, 2009 2:40 pm

Help with this formula!

Post by thirtyfourtwenty »

I have a project that requires a Body Fat Percentage calculator. The formulas I have found are as follows, but when I try to have PHP make the calculation, they don't work. Can someone help with these formulas in PHP?

Formula for Men:
%Fat=495/(1.0324-0.19077(log(waist-neck))+0.15456(log(height)))-450

Formula for Women:
%Fat=495/(1.29579-0.35004(log(waist+hip-neck))+0.22100(log(height)))-450

I tried the formula (for Men), unsuccessfully, using numbers as follows:
495/(1.0324 - .19077(log(31 - 11)) + .15456(log(72))) - 450

Please help! Thanks!!
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: Help with this formula!

Post by requinix »

You have to use * for multiplication.

Not familiar with programming, are you?
webgrrl
Forum Newbie
Posts: 8
Joined: Mon Apr 13, 2009 4:27 pm

Re: Help with this formula!

Post by webgrrl »

The first thing that I noticed was that you didn't use the operator * for multiplication after .19077 and .15456 remember just because in real math puting something in parathesis after a number means multiplication you have to specify that in a programming language. Think of it this way, when you call a function in PHP you use the syntax myFunction() so instead it is going to look for a function with the name of the number you put there. I haven't tried that exactly because I don't have my scientific calculator on me to check, but see if that works.
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: Help with this formula!

Post by requinix »

webgrrl wrote:The first thing that I noticed was that you didn't use the operator * for multiplication after .19077 and .15456 remember just because in real math puting something in parathesis after a number means multiplication you have to specify that in a programming language. Think of it this way, when you call a function in PHP you use the syntax myFunction() so instead it is going to look for a function with the name of the number you put there. I haven't tried that exactly because I don't have my scientific calculator on me to check, but see if that works.
For most languages parentheses don't mean anything. They're like commas: you use them for a greater purpose. That includes math: parentheses don't mean anything there either, they're just used for grouping stuff together.

In math if you stick something next to something else without any kind of symbol in between it automatically means multiplication. PHP is not a mathematical language so it won't assume anything.
Post Reply