1- Calculating Total Marks
Real-life context: Calculating a student’s total marks.
FUNCTION CalculateTotal(Mark1, Mark2, Mark3 : INTEGER) RETURNS INTEGER
DECLARE Total : INTEGER
Total ← Mark1 + Mark2 + Mark3
RETURN Total
ENDFUNCTION
2- Calculating Average Temperature (Weather Station)
Real-life context: Finding the average temperature of a day.
FUNCTION AverageTemperature(T1, T2, T3 : INTEGER) RETURNS INTEGER
DECLARE Avg : INTEGER
Avg ← (T1 + T2 + T3) DIV 3
RETURN Avg
ENDFUNCTION
3-Calculating Bill Amount (Shopping Store)
Real-life context: Calculating the total bill including tax.
FUNCTION CalculateBill(Price, Quantity : INTEGER) RETURNS INTEGER
DECLARE Bill : INTEGER
Bill ← Price * Quantity
RETURN Bill
ENDFUNCTION
4-Checking Eligibility to Vote (Civic System)
Real-life context: Checking if a person can vote.
FUNCTION CanVote(Age : INTEGER) RETURNS BOOLEAN
IF Age >= 18 THEN
RETURN TRUE
ELSE
RETURN FALSE
ENDIF
ENDFUNCTION
5-Converting Minutes to Hours (Daily Time Management)
Real-life context: Converting total minutes into hours.
FUNCTION ConvertToHours(Minutes : INTEGER) RETURNS INTEGER
DECLARE Hours : INTEGER
Hours ← Minutes DIV 60
RETURN Hours
ENDFUNCTION
Exam Tip for Students
- Always use meaningful function names
- Match parameters and return type
- Use RETURN correctly
- Keep logic simple and clear
