TUTORIAL WORKSHEET — EASTER HOLIDAYS
TASK 3 — PROGRAMMING
C Program: Student Marks Calculator
Problem: Write a C program to calculate a student's weighted marks across 4 subjects — Maths
(coeff. 4), Economics (coeff. 2), Geography (coeff. 2), Computer Science (coeff. 2). Total
maximum score = 200. Output: percentage and grade (A / B / C / F).
SUBTASKS 1 – 4 : ALGORITHM (PSEUDOCODE)
The algorithm below fulfils all four requirements: reading marks, calculating weighted total, computing
percentage, and determining grade.
BEGIN
// SUBTASK 1 — Read marks for all 4 subjects
DECLARE maths, economics, geography, comp_sci AS FLOAT
OUTPUT "Enter mark for Maths (out of 20): "
INPUT maths
OUTPUT "Enter mark for Economics (out of 20): "
INPUT economics
OUTPUT "Enter mark for Geography (out of 20): "
INPUT geography
OUTPUT "Enter mark for Computer Science (out of 20): "
INPUT comp_sci
// SUBTASK 2 — Multiply by coefficients and calculate total
// Coefficients: Maths=4, Economics=2, Geography=2, [Link].=2
DECLARE weighted_total AS FLOAT
SET weighted_total ← (maths × 4) + (economics × 2) +
(geography × 2) + (comp_sci × 2)
// SUBTASK 3 — Calculate percentage (total ÷ 200 × 100)
DECLARE percentage AS FLOAT
SET percentage ← (weighted_total / 200) × 100
// SUBTASK 4 — Determine grade
DECLARE grade AS CHARACTER
IF percentage >= 75 AND percentage <= 100 THEN
SET grade ← 'A'
ELSE IF percentage >= 65 AND percentage <= 74 THEN
SET grade ← 'B'
ELSE IF percentage >= 50 AND percentage <= 64 THEN
SET grade ← 'C'
ELSE
SET grade ← 'F' // Below 50%
END IF
// Display results
OUTPUT "Weighted Total : ", weighted_total, " / 200"
OUTPUT "Percentage : ", percentage, "%"
OUTPUT "Grade : ", grade
END
Grade Scale Reference
Grade A Grade B Grade C
75% – 100% 65% – 74% 50% – 64%
SUBTASK 5 : COMPLETE C PROGRAM
The following C program implements the algorithm above using the GCC compiler.
/*
* Task 3 - Programming
* C Program: Student Marks Calculator
* Subjects: Maths (x4), Economics (x2), Geography (x2), CS (x2)
*/
#include <stdio.h>
int main() {
float maths, economics, geography, computer_science;
float weighted_total, percentage;
char grade;
/* Step 1: Read marks for all subjects */
printf("Enter mark for Maths (out of 20): ");
scanf("%f", &maths);
printf("Enter mark for Economics (out of 20): ");
scanf("%f", &economics);
printf("Enter mark for Geography (out of 20): ");
scanf("%f", &geography);
printf("Enter mark for Computer Science (out of 20): ");
scanf("%f", &computer_science);
/* Step 2: Multiply by coefficients and calculate total */
weighted_total = (maths * 4) + (economics * 2)
+ (geography * 2) + (computer_science * 2);
/* Step 3: Calculate percentage (total / 200 * 100) */
percentage = (weighted_total / 200) * 100;
/* Step 4: Determine grade */
if (percentage >= 75 && percentage <= 100) grade = 'A';
else if (percentage >= 65 && percentage <= 74) grade = 'B';
else if (percentage >= 50 && percentage <= 64) grade = 'C';
else grade = 'F';
/* Display results */
printf("Weighted Total : %.1f / 200\n", weighted_total);
printf("Percentage : %.2f%%\n", percentage);
printf("Grade : %c\n", grade);
return 0;
}
SUBTASK 6 : SCREENSHOT OF THE PROGRAM
The screenshot below shows the complete C source code as displayed in a code editor (IDE). The
program was compiled and tested successfully using GCC.
Figure 1: Source code of marks.c — compiled with GCC
Task 3 — Saved as [Link] | Tutorial Worksheet — Easter Holidays