Ask Experts Questions for FREE Help !
Ask
    andyhaus1057's Avatar
    andyhaus1057 Posts: 98, Reputation: 1
    Junior Member
     
    #1

    Jul 16, 2009, 11:00 AM
    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
    albear's Avatar
    albear Posts: 1,594, Reputation: 222
    Ultra Member
     
    #2

    Jul 16, 2009, 11:04 AM

    (stick with me for a minute)

    What if I scored 65, what would me grade be?
    Perito's Avatar
    Perito Posts: 3,139, Reputation: 150
    Ultra Member
     
    #3

    Jul 16, 2009, 11:29 AM

    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.

Not your question? Ask your question View similar questions

 

Question Tools Search this Question
Search this Question:

Advanced Search

Add your answer here.


Check out some similar questions!

C programming [ 2 Answers ]

I'll be extremely thankful if u could provide me with a c program that convert a given nfa to dfa

Something about programming! [ 4 Answers ]

Can anyone help me about this question>>>?? (Microsoft Visual C++) A company wants to transmit data over the telephone, but they are concerned that their phones may be tapped. All of their data is transmitted as four-digit integers. They have asked you to write a program that will encrypt their...

C programming [ 4 Answers ]

Write and test a function hydroxide that takes a chemical formula as a parameter and returns True if the chemical is a hydroxide (i.e. ends in OH) and returns False otherwise. Example: Enter a chemical formula: NaOH NaOH is a hydroxide. Enter a chemical formula: H2O H2O is not a...

Qt programming [ 1 Answers ]

Hi, My name is anshahmed.I am doing final year B.TECH.Now I am doing a project and I want to use qt programming .Whie I was compiling the qt programm the compiler giving errors in header file(qpplicaton.h) .how can I compile the qt programm.


View more questions Search