Constructs of A Pseudocode - Decision or Selection Classroom Excersises
Constructs of A Pseudocode - Decision or Selection Classroom Excersises
MODULE 2
Constructs of a pseudocode - Decision or Selection
BEGIN
PRINT "Enter a number:"
INPUT number
IF number > 100 THEN
PRINT "Number is greater than 100."
END IF
END
2. Problem Statement: Write a pseudocode to check if a person is eligible for a driving license.
The minimum age requirement is 16 years. If the person is 16 or older, print "Eligible for a
driving license." Otherwise, print "Not eligible for a driving license."
BEGIN
PRINT "Enter your age:"
INPUT age
IF age >= 16 THEN
PRINT "Eligible for a driving license."
ELSE
PRINT "Not eligible for a driving license."
END IF
END
3. Problem Statement: Write a pseudocode that assigns a grade based on the marks obtained
by a student:
• If the marks are 90 or above, the grade is "A."
• Otherwise, print "Below A grade."
BEGIN
PRINT "Enter your marks:"
INPUT marks
IF marks >= 90 THEN
PRINT "Grade: A"
ELSE
PRINT "Below A grade."
END IF
END
BEGIN
PRINT "Enter a number:"
INPUT number
IF number MOD 5 = 0 THEN
PRINT "Divisible by 5."
ELSE
PRINT "Not divisible by 5."
END IF
END
5. Problem Statement: Write a pseudocode that checks if a student has passed or failed an
exam. The passing mark is 40 or above. If the student scores 40 or more, print "Pass."
Otherwise, print "Fail."
BEGIN
PRINT "Enter your exam score:"
INPUT score
IF score >= 40 THEN
PRINT "Pass"
ELSE
PRINT "Fail"
END IF
END
6. Problem Statement: Write a pseudocode that checks whether a number is even or odd using
a simple if construct.
BEGIN
PRINT "Enter a number:"
INPUT number
8. Problem Statement: A customer visits an online store that offers a discount based on the
total purchase amount:
• If the total is greater than $500, apply a 20% discount.
• If the total is between $200 and $500 (inclusive), apply a 10% discount.
• If the total is less than $200, no discount is applied.
Write a pseudocode that calculates the final amount after applying the discount.
BEGIN
PRINT "Enter the total purchase amount:"
INPUT total_amount
9. Problem Statement: Create a pseudocode for a simple traffic light system. The system
operates in the following way:
• If the light is green, cars can go.
• If the light is yellow, cars should slow down.
• If the light is red, cars must stop.
Write the pseudocode that determines what message to display based on the light color
input.
BEGIN
PRINT "Enter the traffic light color (green, yellow, red):"
INPUT light_color
10. Problem Statement: Write a pseudocode that checks the strength of a user’s password. The
rules for checking the strength are:
• If the password length is less than 6 characters, it is considered "Weak."
• If the password contains at least 6 characters but less than 10 characters, it is
"Moderate."
• If the password contains 10 or more characters, it is "Strong."
BEGIN
PRINT "Enter your password:"
INPUT password
password_length = LENGTH(password)
CASEOF (dayOfWeek)
CASE "Monday":
PRINT "It's the start of the week."
BREAK
CASE "Tuesday":
PRINT "It's the second day of the week."
BREAK
CASE "Wednesday":
PRINT "Mid-week!"
BREAK
CASE "Thursday":
PRINT "Almost the weekend."
BREAK
CASE "Friday":
PRINT "Weekend is near!"
BREAK
CASE "Saturday", "Sunday":
PRINT "It's the weekend!"
BREAK
DEFAULT:
PRINT "Invalid day entered."
END CASE
END
12. Create a pseudocode program that accepts a numerical score (0-100) as input and assigns a
letter grade (A, B, C, D, F) based on that score using a case structure. For example, if the score
is between 90 and 100, the grade should be "A". Ensure the program handles scores outside
the 0-100 range by displaying an error message.
START
Declare score as Integer
Input score
CASEOF (score)
CASE score >= 90 AND score <= 100:
PRINT "Grade A"
BREAK
CASE score >= 80 AND score < 90:
PRINT "Grade B"
BREAK
CASE score >= 70 AND score < 80:
PRINT "Grade C"
BREAK
CASE score >= 60 AND score < 70:
PRINT "Grade D"
BREAK
CASE score < 60:
PRINT "Grade F"
BREAK
DEFAULT:
PRINT "Invalid score entered."
END CASE
END
13. Write a pseudocode program that functions as a simple calculator. The program should take
two numbers and an operator (+, -, *, /) as input and use a case structure to perform the
corresponding mathematical operation. If the user inputs a division by zero, the program
should display an error message instead of attempting the calculation. After the operation, the
program should print the result.
START
Declare number1, number2 as Float
Declare operator as Character
Input number1
Input number2
Input operator
CASEOF (operator)
CASE '+':
result = number1 + number2
PRINT "Result: " + result
BREAK
CASE '-':
result = number1 - number2
PRINT "Result: " + result
BREAK
CASE '*':
result = number1 * number2
PRINT "Result: " + result
BREAK
CASE '/':
IF number2 != 0:
result = number1 / number2
PRINT "Result: " + result
ELSE:
PRINT "Cannot divide by zero"
BREAK
DEFAULT:
PRINT "Invalid operator"
END CASE
END
14. Develop a pseudocode program that simulates a traffic light control system using a case
structure. The program should take a color input (Red, Yellow, or Green) and print the
corresponding action ("Stop", "Prepare to stop", or "Go"). If the input color is not valid, display
an error message.
START
Declare lightColor as String
Input lightColor
CASEOF (lightColor)
CASE "Red":
PRINT "Stop"
BREAK
CASE "Yellow":
PRINT "Prepare to stop"
BREAK
CASE "Green":
PRINT "Go"
BREAK
DEFAULT:
PRINT "Invalid light color"
END CASE
END
15. Create a pseudocode program that takes the number of a month (1 for January, 2 for February,
etc.) as input and uses a case structure to print how many days are in that month. For
simplicity, assume February always has 28 days. Group the months with the same number of
days into one case in the case structure where possible. If an invalid month number is input
(e.g., 13), display an error message
START
Declare month as Integer
Input month
CASEOF (month)
CASE 1, 3, 5, 7, 8, 10, 12:
PRINT "31 days"
BREAK
CASE 4, 6, 9, 11:
PRINT "30 days"
BREAK
CASE 2:
PRINT "28 days"
BREAK
DEFAULT:
PRINT "Invalid month entered."
END CASE
END
16. Write a pseudocode program that evaluates a student's performance based on their letter
grade (A, B, C, D, F) using a case structure. The program should take the grade as input and
print a corresponding performance message, such as "Excellent" for an "A" or "Fail" for an "F".
Ensure the program can handle invalid grades by displaying an error message.
START
Declare grade as Character
Input grade
CASEOF (grade)
CASE 'A':
PRINT "Excellent"
BREAK
CASE 'B':
PRINT "Good"
BREAK
CASE 'C':
PRINT "Average"
BREAK
CASE 'D':
PRINT "Poor"
BREAK
CASE 'F':
PRINT "Fail"
BREAK
DEFAULT:
PRINT "Invalid grade"
END CASE
END