# Thread: Calculating body weight.

1. ## 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

2. Sure. Here is my reply:

Code:
`// answer`
Just kidding.

A simple rule to estimate your ideal body weight is to allow 110 pounds for the first 5 feet of height...
Assume the person is at least 5 feet tall.
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.

3. -thinks intently-...

Sorry...I got nothin'...

4. 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.

5. I have. And I have gotten nowhere.

6. Here's something....

ideal = 110 + 5 * inches = 5ft + 5 inches

7. //get height
//convert height to inches
//subtract 5 foot to get 'height_over_5_foot'
//calc weight as 110 + 'height_over_5_foot' * 5

8. I'm sorry...call me stupid...but none of this is clicking for me...

9. 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

10. 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?

11. This equation works for heights exceeding 5 feet, but not lower than 5 feet.

Code:
`ideal = 110 + (inches * 5) + 60;`

12. So looking at your instructions:
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

13. Do I need an "if" statement at all?

14. Probably not.

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

Jim

15. I have been thinking math. That's my problem. I just don't know what I am missing.

Popular pages Recent additions