Using an Array to Store User Input and Perform Calculations

Using an Array to Store User Input and Perform Calculations

A simple program consisting of three parts: getGrades(), averageGrades(), and main() (as the driver function).

The getGrades() function accepts 10 grades from the user and stores them in array listGrades[]. That array is then used by averageGrades() to sum all grades and calculate the average, which is stored in the last index space of the array. main() then displays the average of the 10 grades. Both getGrades() and averageGrades() use a for loop to manipulate listGrades[].

The array size is int countGrades + 1, so is easily changeable based on the value of countGrades, which is hard coded as 10 in this example. However, the program can easily be modified to ask the user for countGrades.

Leave a Reply

Your email address will not be published. Required fields are marked *