Thread: Stuck on project C#

  1. #1
    Registered User
    Join Date
    Feb 2022
    Posts
    6

    Exclamation Stuck on project C#

    I'm stack in this project, I need help figuring out how to write these formulas correctly in C#:

    Women Thirty Years and Younger

    hips + (.80 x thigh) – (2 x calf) – wrist = % body fat

    Women over Thirty

    hips + thigh – (2 x calf) – wrist = % body fat

    Men Thirty Years and Younger

    waist + (1/2 hips) – (3 x forearm) – wrist = % body fat

    Men over Thirty

    waist + (1/2 hips) – (2.7 x forearm) – wrist = % body fat

    Men

    Lean Body Mass (pounds) 0.85 = correct weight to be 15% fat

    Women

    Lean Body Mass (pounds) 0.78 = correct weight to be 22% fat


    I have attached a screenshots please take a look.
    3 — ImgBB
    33 — ImgBB
    Stuck on project C#-3-jpg
    Stuck on project C#-33-png
    Last edited by Kab; 02-03-2022 at 05:36 PM.

  2. #2
    Registered User
    Join Date
    Jan 2022
    Posts
    6
    This is college level Math Class (System) | Microsoft Docs
    This is elementary level: C# Variables with Examples - Tutlane
    Good luck screwing this up, mate.

  3. #3
    Registered User
    Join Date
    Feb 2022
    Posts
    6
    Quote Originally Posted by natty View Post
    This is college level Math Class (System) | Microsoft Docs
    This is elementary level: C# Variables with Examples - Tutlane
    Good luck screwing this up, mate.
    I still need help

  4. #4
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,154
    Pictures of your UI are fine.

    Pictures of your code are useless.
    Paste code between [code][/code] tags so we can meaningfully quote and refer to it.

    > waist + (1/2 hips) – (3 x forearm) – wrist = % body fat
    Like say
    Code:
    percent_body_fat = waist + (0.5 * hips) - ( 3 * forearm ) - wrist;
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  5. #5
    Registered User
    Join Date
    Feb 2022
    Posts
    6
    Okay, what else is needed to make the application run correctly ?

  6. #6
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,154
    > Okay, what else is needed to make the application run correctly ?
    Some effort on your part.

    You already have an example of how to check for one of the radio buttons.

    In pseudo code, it's
    Code:
    if ( male ) {
      if ( over_thirty ) {
      } else if (  thirty_and_under )
      }
    } else if ( female ) {
      if ( over_thirty ) {
      } else if (  thirty_and_under )
      }
    }
    Each of those 4 cases calculates a percent_body_fat using the formulae you've been given.

    Now show some code.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  7. #7
    Registered User
    Join Date
    Feb 2022
    Posts
    6
    Here is what I have done so far but still struggling and 6 errors



    Code:
    UserWeight = double.Parse(txtWeight.Text);
                lblWrist = double.Parse(txtMeasurement4.Text);
                lblHips = double.Parse(txtMeasurement2.Text);
                lblForearm = double.Parse(txtMeasurement3.Text);
                lblWaist = double.Parse(txtMeasurement1.Text);
    
    
    
    
                if (rdoMale.Checked == true)
    
                    if (rdo30Under.Checked == true)
                    {
                        percentfat = (lblHips + (.5 * lblHips) - (2 * lblForearm) - lblWrist); }
                if (rdo30Under.Checked == true)
                    percentfat = (lblHips + (.5 * lblHips) - (2.7 * lblForearm) - lblWrist); 
                if (rdoFemale.Checked == true) 
    
                if (rdo30Under.Checked == true) 
                percentfat = (lblWaist + lblHips) - (2  *lblForearm) - lblWrist);
    
                    Fatlbs = UserWeight * (.01 * percentfat);
                Leanlbs = UserWeight - Fatlbs;
    
                if (rdoMale)
    
                if (rdoMale.Checked == true)
                {
                    idealWeight = ((Leanlbs) / (.85));
                }
                else if (rdoFemale.Checked == true) {
                    idealWeight = ((Leanlbs) / (.78));
    
                }
    
                Fatlbs = Math.Round(Fatlbs, 0);
                Leanlbs = Math.Round(Leanlbs, 0);
                Leanlbs.ToString("00");
                percentfat.ToString("00");
                Fatlbs.ToString("00");
                double v = Math.Round(idealWeight);
                v.ToString();

  8. #8
    Registered User
    Join Date
    Sep 2020
    Posts
    145
    What errors do you get ?
    I would break up the code into 2 different functions. One to calculate for men and one for women

  9. #9
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,154
    Slow down and test as you go.

    Don't try and write the whole thing, then wonder why it's full of errors and/or doesn't work.

    Code:
    if ( male ) {
      if ( over_thirty ) {
      } else if (  thirty_and_under )
      }
    } else if ( female ) {
      if ( over_thirty ) {
      } else if (  thirty_and_under )
      }
    }
    Without filling in any calculations, make sure this logic actually compiles before trying to do anything else.

    Then add one calculation like so.
    Code:
    if ( male ) {
      if ( over_thirty ) {
        percentfat = // whichever it is.
      } else if (  thirty_and_under )
      }
    } else if ( female ) {
      if ( over_thirty ) {
      } else if (  thirty_and_under )
      }
    }
    
    // Then however you write to your results text field
    result = "Fat = " + ToString.to_string();
    Check that when you select male over 30 in your radio buttons and type in some values into your other dialogs, that the final result is OK when you press calculate.

    Then do the same for the other calculations.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 4
    Last Post: 08-02-2013, 06:45 PM
  2. Replies: 5
    Last Post: 02-23-2013, 03:37 PM
  3. Stuck with coding while Senior Project Due!!!!
    By kuro_ng in forum C Programming
    Replies: 24
    Last Post: 05-25-2011, 03:33 PM
  4. Paid project - The Free Marketing Project
    By sharefree in forum Projects and Job Recruitment
    Replies: 0
    Last Post: 10-27-2010, 02:15 PM
  5. your 11th & 12th grade c++ project or similar project
    By sleepyheadtony in forum A Brief History of Cprogramming.com
    Replies: 12
    Last Post: 01-13-2002, 05:14 PM

Tags for this Thread