/**************************************************************************** * array.c * * Computer Science 50 * David J. Malan * * Computes a student's average across 3 quizzes (without dropping lowest). * * Demonstrates use of an array, a constant, a multiline string, and * rounding. ***************************************************************************/ #include #include /* number of quizzes per term */ #define QUIZZES 3 int main(int argc, char * argv[]) { float grades[QUIZZES]; int average, i, sum; /* ask user for grades */ printf("\nWhat were your quiz scores?\n\n"); for (i = 0; i < QUIZZES; i++) { printf("Quiz #%d of %d: ", i+1, QUIZZES); grades[i] = GetFloat(); } /* compute average */ sum = 0; for (i = 0; i < QUIZZES; i++) sum += grades[i]; average = (int) (sum / (float) QUIZZES + 0.5); /* report average */ printf("\nWithout dropping your lowest score, " \ "your average is: %d\n\n", average); }