Ask Me Help Desk

Ask Me Help Desk (https://www.askmehelpdesk.com/forum.php)
-   Other Programming (https://www.askmehelpdesk.com/forumdisplay.php?f=437)
-   -   Pseudocode programming (https://www.askmehelpdesk.com/showthread.php?t=376368)

  • Jul 16, 2009, 11:00 AM
    andyhaus1057
    Pseudocode programming
    This pseudocode contains several nested If-Then-Else statements. It was written without proper alignment and indentation. How would I rewrite the code and use proper conventions of alignment and indentation?

    If score < 60 Then
    Display “Your grade is F.”
    Else
    If score <70 Then
    Display “Your grade is D.”
    Else
    If score <80 Then
    Display “Your grade is C.”
    Else
    If score <90 Then
    Display “Your grade is B.”
    Else
    Display “Your grade is A.”
    End If
    End If
    End If
    End if
  • Jul 16, 2009, 11:04 AM
    albear

    (stick with me for a minute)

    What if I scored 65, what would me grade be?
  • Jul 16, 2009, 11:29 AM
    Perito

    There are different standards for indenting, and your standards may differ. This is how I would do it, but I know that others would do it differently.

    If score < 60 Then
    &#160;&#160;&#160;&#160;Display “Your grade is F.”
    Else
    &#160;&#160;&#160;&#160;If score <70 Then
    &#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;Di splay “Your grade is D.”
    &#160;&#160;&#160;&#160;Else
    &#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160 ;If score <80 Then
    &#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&# 160;&#160;&#160;&#160;Display “Your grade is C.”
    &#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;El se
    &#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&# 160;&#160;&#160;&#160;If score <90 Then
    &#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&# 160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;Disp lay “Your grade is B.”
    &#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&# 160;&#160;&#160;&#160;Else
    &#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&# 160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;Disp lay “Your grade is A.”
    &#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&# 160;&#160;&#160;&#160;End If
    &#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;En d If
    &#160;&#160;&#160;&#160;End If
    End if

    I prefer that IF, ELSE, and END IF line up in the same column for each IF statement. One common variation is to put the ELSE at the end of the previous line similar to how THEN is placed. Some people put THEN on the next line and indent the command additionally.

    Quote:

    Originally Posted by albear View Post
    (stick with me for a minute)

    what if i scored 65, what would me grade be?

    The first line, "If score < 60" is FALSE so program flow falls through to the else. In the next IF statement, "If score <70", that would be TRUE, so the program would print "Your grade is D". It would then have no further IF statements to process.

  • All times are GMT -7. The time now is 06:43 PM.