Paper 2 scenario practice
Temperature conversion using a function
The scenario
A weather app needs to convert Celsius to Fahrenheit. The developer wants:
1. A FUNCTION called CelsiusToFahrenheit that takes ONE parameter (a temperature in Celsius, REAL) and RETURNS the converted Fahrenheit value (REAL).
- Conversion formula: F = C × 9/5 + 32.
2. A main program that:
- Reads 5 Celsius temperatures (one at a time).
- For each, calls the function and outputs the original Celsius value AND the converted Fahrenheit value.
Write a program in pseudocode (or a high-level language of your choice). Marks will be awarded for correct function declaration, parameter handling, the RETURN statement, and proper integration with the main program.
Marking scheme — total 15 marks
Cambridge IGCSE 0478 Paper 2
- 3Function header: FUNCTION CelsiusToFahrenheit(c : REAL) RETURNS REAL — declares the function name, the parameter with its type, and the return type.
- 3Function body and RETURN: Inside the function: compute fahrenheit ← c * 9 / 5 + 32 (or directly RETURN c * 9 / 5 + 32). The RETURN statement is essential — without it the function produces no value.
- 3Main program loop: FOR loop running exactly 5 times. INPUT the Celsius value each iteration.
- 4Function call and output: CALL the function with the input value (or assign its return value to a variable). OUTPUT both the Celsius value and the returned Fahrenheit value, with labels making it clear which is which.
- 2Program structure and naming: FUNCTION/ENDFUNCTION paired; sensible parameter and variable names; main program reads top-to-bottom.
Hints — reveal one at a time, only if stuck
Your pseudocode workspace
1 line