home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Sams Teach Yourself C in 21 Days (6th Edition)
/
STYC216E.ISO
/
mac
/
Examples
/
Day08
/
grades.c
< prev
next >
Wrap
C/C++ Source or Header
|
2002-04-26
|
788b
|
37 lines
/*grades.c - Sample program with array */
/* Get 10 grades and then average them */
#include <stdio.h>
#define MAX_GRADE 100
#define STUDENTS 10
int grades[STUDENTS];
int idx;
int total = 0; /* used for average */
int main( void )
{
for( idx=0;idx< STUDENTS;idx++)
{
printf( "Enter Person %d's grade: ", idx +1);
scanf( "%d", &grades[idx] );
while ( grades[idx] > MAX_GRADE )
{
printf( "\nThe highest grade possible is %d",
MAX_GRADE );
printf( "\nEnter correct grade: " );
scanf( "%d", &grades[idx] );
}
total += grades[idx];
}
printf( "\n\nThe average score is %d\n", ( total / STUDENTS) );
return (0);
}