0% found this document useful (0 votes)
4 views2 pages

Algorithm

The document outlines a program that includes a password validation step followed by a main menu loop with options to enter marks and calculate GPA, calculate age, or exit. Users have three attempts to enter the correct course code as a password before the program terminates. The program also includes input validation for marks and age calculations based on user-provided birth dates.

Uploaded by

anitangabire017
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views2 pages

Algorithm

The document outlines a program that includes a password validation step followed by a main menu loop with options to enter marks and calculate GPA, calculate age, or exit. Users have three attempts to enter the correct course code as a password before the program terminates. The program also includes input validation for marks and age calculations based on user-provided birth dates.

Uploaded by

anitangabire017
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

START

// Step 1: Password Validation

INPUT full name

SET courseCode = "CMP2103"

SET attempts = 0

WHILE attempts < 3

PROMPT user to enter course code as password

IF password == courseCode

DISPLAY "Password validated. Welcome!"

BREAK

ELSE

DISPLAY "Incorrect password. Try again."

INCREMENT attempts by 1

IF attempts == 3

DISPLAY "Program terminated due to incorrect password."

EXIT

// Step 2: Main Menu Loop

DO

DISPLAY "Menu: 1. Enter Marks and Calculate GPA (Max GPA = 5), 2. Calculate Age, 3. Exit"

INPUT choice

SWITCH(choice)

CASE 1:

// Step 3: Marks Input and GPA Calculation

PROMPT user for number of subjects

SET totalMarks = 0

FOR each subject

DO

PROMPT user for a mark between 0 and 100


WHILE mark is invalid

ADD mark to totalMarks

CALCULATE GPA = (totalMarks / (number of subjects * 100)) * 5

DISPLAY GPA (Max GPA = 5)

BREAK

CASE 2:

// Step 4: Age Calculation

GET current date

PROMPT user for birth date (DD/MM/YYYY)

CALCULATE age in years, months, and days

ADJUST age calculation for days and months if needed

DISPLAY age in years, months, and days

BREAK

CASE 3:

DISPLAY "Exiting program."

EXIT

DEFAULT:

DISPLAY "Invalid input. Please select a valid option."

WHILE choice != 3

END

You might also like