Total and average of marks
Reads five marks with INPUT inside a FOR loop, keeps a running total and outputs the average.
Input and outputLoops
// Read five marks and output the total and average
DECLARE Mark : INTEGER
DECLARE Total : INTEGER
DECLARE Count : INTEGER
CONSTANT NumberOfMarks <- 5
Total <- 0
FOR Count <- 1 TO NumberOfMarks
OUTPUT "Enter mark ", Count
INPUT Mark
Total <- Total + Mark
NEXT Count
OUTPUT "Total: ", Total
OUTPUT "Average: ", Total / NumberOfMarks- Inputs
- 12, 15, 9, 18, 11
- Output
Enter mark 1 Enter mark 2 Enter mark 3 Enter mark 4 Enter mark 5 Total: 65 Average: 13