# Calculating body weight.

Show 80 post(s) from this thread on one page
Page 1 of 2 12 Last
• 08-29-2012
mc74
Calculating body weight.
Hello everyone! I hope someone can help me. I'm not very good with programming, so please bear with me, because I'm sure this is very simple for better programmers. But I digress. I am trying to write a C++ program to calculate your "ideal body weight".

Here is the question/story:

A simple rule to estimate your ideal body weight is to allow 110 pounds for the first 5 feet of height and 5 pounds for each additional inch. Write a program with a variable for the height of a person in feet and another variable for the additional inches and input values for these variables from the keyboard. Assume the person is at least 5 feet tall. For example, a person that is 6 feet and 3 inches tall would be represented with a variable that stores the number 6 and another variable that stores the number 3. Based on these values calculate and output the ideal body weight.

And here is the code I have so far!

Code:

```#include <iostream> using namespace std; int main( ) {     int feet;     int inches;     int ideal;     cout << "Please enter how many feet tall you are: ";     cin >> feet;     cout << "Please enter the additional inches of your height: ";     cin >> inches;         //math equation         cout << "Your ideal body weight is"         return 0; }```
I'm not very good with math, so that is where I am having the most trouble!

Thank you, for any help/feedback!

Kyle
• 08-29-2012
Matticus

Code:

`// answer`
Just kidding.

Quote:

A simple rule to estimate your ideal body weight is to allow 110 pounds for the first 5 feet of height...
Quote:

Assume the person is at least 5 feet tall.
Quote:

5 pounds for each additional inch.
Based on this information, you have a weight based on [a minimum of] five feet of height.

Also based on this information, you know how much to add to this amount for each "inch" of height.

"Feet" have to be converted to inches, which is then added to this amount as per the previous line of my post.

Try out these vague directions and show us what you come up with.
• 08-30-2012
mc74
-thinks intently-...

Sorry...I got nothin'...

:(
• 08-30-2012
Matticus
Are you just thinking about it in your head? Have you tried to sit down with a pen and paper? Some people (myself included) are better able to solve problems by scribbling on a sheet of paper - sometimes this helps find an answer.

There's not really much more I can say without giving away the solution, and I wouldn't want to do that because it would rob you of a learning experience.
• 08-30-2012
mc74
I have. And I have gotten nowhere.
• 08-30-2012
mc74
Here's something....

ideal = 110 + 5 * inches = 5ft + 5 inches
• 08-30-2012
novacain
//get height
//convert height to inches
//subtract 5 foot to get 'height_over_5_foot'
//calc weight as 110 + 'height_over_5_foot' * 5
• 08-31-2012
mc74
I'm sorry...call me stupid...but none of this is clicking for me...
• 08-31-2012
jimblumberg
This really seems more like you don't really understand the problem and really has nothing to do with writing a program. I suggest you put the computer away, and bring out and study your math books. It seems to me that you don't have a clue about how to do the mathematics required to solve this problem. Until you understand how to do the basic math you will not be able to write a program to solve this basic math problem.

If I am wrong then prove it to me. Show me in English the steps you took to solve this problem, without a computer. Show me the formulas that you used. Show me what numbers you used, and the results these numbers produced.

Jim
• 08-31-2012
mc74
Here's some up dated code:

Code:

```#include <iostream> using namespace std; int main( ) {     int feet;     int inches;     int ideal;         cout << "Please enter how many feet tall you are: ";     cin >> feet;     cout << "Please enter the additional inches of your height: ";     cin >> inches;     //math equation     ideal = 110 + (inches * 5);     cout << "Your ideal body weight is: " << ideal << "\n\n";     return 0; }```
It works, and I get the correct "ideal weight" for anything in the 5 foot range, but anything higher it will not compute. What am I missing?
• 08-31-2012
mc74
This equation works for heights exceeding 5 feet, but not lower than 5 feet.

Code:

`ideal = 110 + (inches * 5) + 60;`
• 08-31-2012
jimblumberg
Quote:

A simple rule to estimate your ideal body weight is to allow 110 pounds for the first 5 feet of height and 5 pounds for each additional inch. Write a program with a variable for the height of a person in feet and another variable for the additional inches and input values for these variables from the keyboard. Assume the person is at least 5 feet tall. For example, a person that is 6 feet and 3 inches tall would be represented with a variable that stores the number 6 and another variable that stores the number 3. Based on these values calculate and output the ideal body weight.
How would you allow 110 pounds for the first 5 feet of height?

How do you add 5 pounds for each inch over the initial 5 feet?

Jim
• 08-31-2012
mc74
Do I need an "if" statement at all?
• 08-31-2012
jimblumberg
Probably not.

Remember this is a math problem, not really a programming problem. THINK MATH!

Jim
• 08-31-2012
mc74
I have been thinking math. That's my problem. I just don't know what I am missing.
Show 80 post(s) from this thread on one page
Page 1 of 2 12 Last