none
Calculation formula won't work RRS feed

  • Question

  • Hello!

    I'm new in to making formulas for calculation, so forgive me my clumsiness. Let me give you a sketch of the situation:

    I want to calculate the ideal body weight. However, this is different for men and women. So i defined gender as male or female earlier in the program. The calculation of the ideal body weight for men is 50+0.9*(length-152) and for women 45.5+0.9*(length-152) respectively. 

    So far, i thought it would work if i use the following formula:

    if {gender}=''male'';50+0.9*({length}-152);45.5+0.9*({length}-152);

    However, i get a syntax error '';'' is expected... I tried several options to fix this, however none of them did solve the problem. 

    Can you help me in understanding what went wrong here? 

    Thank you very much in advance

    Wednesday, October 11, 2017 8:19 AM

Answers

  • I don't know if your example is pseudo-code or actual code, but see here for the syntax of using 'if' statements in C#.

    For example:

    if (gender=="male")
    {
       answer = 50 + 0.9 * (length - 152);
    }
    else
    {
       answer = 45.5 + 0.9 * (length - 152);
    }

    Note that when you test for equality you use double = signs (gender=="male").

    When you assign a value into a variable you use single = .

    The semi-colons come at the end of the statements within the {} blocks, not anywhere else in the 'if' clauses.

    • Edited by RJP1973 Wednesday, October 11, 2017 8:33 AM
    • Marked as answer by Meepmus Wednesday, October 11, 2017 8:41 AM
    Wednesday, October 11, 2017 8:31 AM

All replies

  • I don't know if your example is pseudo-code or actual code, but see here for the syntax of using 'if' statements in C#.

    For example:

    if (gender=="male")
    {
       answer = 50 + 0.9 * (length - 152);
    }
    else
    {
       answer = 45.5 + 0.9 * (length - 152);
    }

    Note that when you test for equality you use double = signs (gender=="male").

    When you assign a value into a variable you use single = .

    The semi-colons come at the end of the statements within the {} blocks, not anywhere else in the 'if' clauses.

    • Edited by RJP1973 Wednesday, October 11, 2017 8:33 AM
    • Marked as answer by Meepmus Wednesday, October 11, 2017 8:41 AM
    Wednesday, October 11, 2017 8:31 AM
  • Thank you very much for your quick answer!

    I am not able to say if it's actual code or pseude code, i'm sorry, im really not familiar with coding. 

    The code you've sent did work with a few adjustments. It know looks like this:

    if ({gender}=="0")
    {
       answer = 50 + 0.9 * ({length} - 152);
    }
    else
    {
       answer = 45.5 + 0.9 * ({length} - 152);
    }

    I had to define the variables between {}. 

    Thank you very much again!

    Wednesday, October 11, 2017 8:41 AM