Programming 2
______________________________________________________________________________________________________________________________________________________________________________________________________________________
CTI 110 Page 2
______________________________________________________________________________________________________________________________________________________________________________________________________________________
EXAMPLES: Nesting AND Logical Operator decision structures
Same requirement different structures (nested, nested and, nested or)
Nested
Pseudocode
Function Main
... Chart Style Classic
Declare Integer menuChoice
Assign menuChoice = 0
Output "Menu"
Output "Option 1"
Output "Option 2"
Output "Option 3"
Output "Option 4 to exit"
Input menuChoice
If menuChoice == 1
Output "You chose 1"
False:
If menuChoice == 2
Output "You chose 2"
False:
If menuChoice == 3
Output "You chose 3"
False:
If menuChoice == 4
False:
Output "Invalid Choice"
End
End
End
End
End
FlowcharT
Nested - Logical Operator OR
Pseudocode
Function Main
... Chart Style Classic
Declare Integer menuChoice
Assign menuChoice = 0
Output "Menu"
Output "Option 1"
Output "Option 2"
Output "Option 3"
Output "Option 4 to exit"
Input menuChoice
If menuChoice=1 OR menuChoice=2 OR menuChoice=3
Output "You chose "&menuChoice
False:
If menuChoice == 4
False:
Output "Invalid Choice"
End
End
Output "Goodbye"
End
Flowchart
Nested Logical Operator AND
Pseudocode
Function Main
... Chart Style Classic
Declare Integer menuChoice
Assign menuChoice = 0
Output "Menu"
Output "Option 1"
Output "Option 2"
Output "Option 3"
Output "Option 4 to exit"
Input menuChoice
If menuChoice!=1 AND menuChoice!=2 AND menuChoice!=3
If menuChoice == 4
False:
Output "Invalid Choice"
End
False:
Output "You chose "&menuChoice
End
Output "Goodbye"
End
Flowchart