Programming 2

profileShane0301
Practice-Operators1.docx

______________________________________________________________________________________________________________________________________________________________________________________________________________________

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

Diagram, schematic  Description automatically generated

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

Diagram  Description automatically generated

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

Diagram  Description automatically generated

image2.png

image3.png

image4.png