P4: Grade Average
Grade Average Calculator Program
Explanation
The program starts by asking the user how many grades they want to enter. This number is used to create an array of that size.
It then enters a loop where the user is prompted to enter each grade. Each grade is stored in the array, and its value is added to a total sum.
After all grades are entered, the program calculates the average by dividing the total sum by the number of grades.
Finally, the average grade is displayed, formatted to two decimal places.
This program effectively demonstrates the use of arrays to store a collection of items (grades in this case), along with basic loop usage and arithmetic operations to calculate the average
A variation of the same program
Let us now see a variation of the same program, but with two differences.
The grades are hardcoded and
we are using for-each loop instead of a classical for loop.
Last updated