Like Tree4Likes

Calculating body weight.

This is a discussion on Calculating body weight. within the C++ Programming forums, part of the General Programming Boards category; Hello everyone! I hope someone can help me. I'm not very good with programming, so please bear with me, because ...

  1. #1
    Registered User
    Join Date
    Aug 2012
    Posts
    23

    Question 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
    Last edited by mc74; 08-29-2012 at 07:24 PM.

  2. #2
    Registered User
    Join Date
    Jun 2011
    Posts
    2,061
    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. #3
    Registered User
    Join Date
    Aug 2012
    Posts
    23
    -thinks intently-...

    Sorry...I got nothin'...


  4. #4
    Registered User
    Join Date
    Jun 2011
    Posts
    2,061
    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. #5
    Registered User
    Join Date
    Aug 2012
    Posts
    23
    I have. And I have gotten nowhere.

  6. #6
    Registered User
    Join Date
    Aug 2012
    Posts
    23
    Here's something....

    ideal = 110 + 5 * inches = 5ft + 5 inches
    Last edited by mc74; 08-30-2012 at 08:11 PM.

  7. #7
    train spotter
    Join Date
    Aug 2001
    Location
    near a computer
    Posts
    3,854
    //get height
    //convert height to inches
    //subtract 5 foot to get 'height_over_5_foot'
    //calc weight as 110 + 'height_over_5_foot' * 5
    Swadesh likes this.
    "Man alone suffers so excruciatingly in the world that he was compelled to invent laughter."
    Friedrich Nietzsche

    "I spent a lot of my money on booze, birds and fast cars......the rest I squandered."
    George Best

    "If you are going through hell....keep going."
    Winston Churchill

  8. #8
    Registered User
    Join Date
    Aug 2012
    Posts
    23
    I'm sorry...call me stupid...but none of this is clicking for me...

  9. #9
    Registered User
    Join Date
    May 2010
    Posts
    2,560
    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
    Last edited by jimblumberg; 08-31-2012 at 01:41 PM.
    ZuK and iMalc like this.

  10. #10
    Registered User
    Join Date
    Aug 2012
    Posts
    23
    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. #11
    Registered User
    Join Date
    Aug 2012
    Posts
    23
    This equation works for heights exceeding 5 feet, but not lower than 5 feet.

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

  12. #12
    Registered User
    Join Date
    May 2010
    Posts
    2,560
    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. #13
    Registered User
    Join Date
    Aug 2012
    Posts
    23
    Do I need an "if" statement at all?

  14. #14
    Registered User
    Join Date
    May 2010
    Posts
    2,560
    Probably not.

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

    Jim

  15. #15
    Registered User
    Join Date
    Aug 2012
    Posts
    23
    I have been thinking math. That's my problem. I just don't know what I am missing.

Page 1 of 2 12 LastLast
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Weight Conversion Program
    By AKalair in forum C Programming
    Replies: 12
    Last Post: 11-21-2007, 11:31 AM
  2. Weight Change Program - Help
    By battousaih in forum C Programming
    Replies: 14
    Last Post: 10-01-2007, 04:34 PM
  3. Your Weight On Planets
    By Trekkie in forum C++ Programming
    Replies: 16
    Last Post: 10-23-2005, 11:01 PM
  4. Guaranteed weight loss
    By Glirk Dient in forum A Brief History of Cprogramming.com
    Replies: 8
    Last Post: 05-12-2004, 06:11 AM
  5. losing weight
    By Shadow in forum A Brief History of Cprogramming.com
    Replies: 20
    Last Post: 10-21-2002, 05:43 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21