Algorithms and Data Structures - Case Selection Structure
Algorithms and Data Structures - Case Selection Structure
A human being can lose everything in life, but if they lose faith, certainly
will be ruined.
Script
1.Case structure
2.Exercises
STRUCTURE CHOICE...CASE
Syntax:
When entering this type of CHOICE structure, condition1 is tested with the
variable: if it is TRUE, execute command1 and, after its completion, the flow of
execution continues with the first instruction after the end of the construction (ENDCHOICE);
If condition1 is FALSE, condition2 is tested, and if this is TRUE, the
command2 is executed and, upon completion, the execution continues with the next instruction
at the end of the construction (FIMESCOLHA). This same reasoning is applied to all of the
construction conditions. If by chance all conditions are evaluated as
FALSE, the Command A, which corresponds to the ELSE of the construction, is executed.
SOLUTION EXERCISE:
Resolution:
Calculator algorithm
Var
X,Y: Integer;
Page 1 of 3
Algorithm and data structure 06
Operator: Character;
BEGINNING
Write("Enter X:"); Read(X);
Write("Type Y:"); Read(Y);
Write('Enter the Operation:'); Read(Operator);
CHOOSE Operator
CASE '+'
Write(X + Y)
CASE ‘-’
Write(X - Y)
CASE '*'
Write(X * Y)
CASE '/'
Write(X / Y)
OUTROCASE
Write("Invalid operation");
ENDCHOICE
FIMALGORITHM
FIXATION EXERCISE
3) Multiple choice 2 - Enrich the program above the multiple choice question
choose, including another question on a different topic. At the beginning of the program,
offer the user the choice of which question they want to answer.
AGE CATEGORY
From 05 to 10 Children
From 11 to 15 Youth
From 16 to 20 Junior
Page 2 of 3
Algorithm and data structure 06
From 21 to 25 Professional
Build a program that requests the name and age of an athlete and prints it.
your category.
Page 3 of 3