Sunday, August 2, 2009

What is a good c++ function that prints the average test score from a file?

It's pretty simple, use a for loop and divide the sum of the scores by the number of scores:





int testScores[5] = { 90, 70, 56, 88, 82 };


int sum = 0;


float average;





for (int i = 0; i %26lt; 5; i++)


sum += testScores[i];





average = (float)sum / 5.0f;

bouquet

No comments:

Post a Comment