// C code
// This program will calculate the average of 3 exams for 5 students.
// Developer: Faculty CMIS102
// Date: Jan 31, XXXX
#include <stdio.h>
int main ( )
{
/* variable definition: */
char StudentName[ 100 ] ;
float ExamValue, Sum, Avg;
int students, exams, & num_values;
printf ( "How many students to find the average for?" ) ; scanf ( "%d" , & num_values
) ;
// Loop through 5 Students
for ( students= 0 ; students < & num_values ; students++ )
{
// reset Sum to 0
Sum = 0.0 ;
printf ( "Enter Student Name \n " ) ; scanf ( "%s" , StudentName
) ; // Nested Loop for Exams
for ( exams= 0 ; exams < 3 ; exams++ )
{
printf ( "Enter exam grade: \n " ) ; Sum += ExamValue;
}
Avg = Sum/ 3.0 ;
printf ( "Average for %s is %f\n " , StudentName
, Avg
) ; }
return 0 ;
}
Ly8gQyBjb2RlCi8vIFRoaXMgcHJvZ3JhbSB3aWxsIGNhbGN1bGF0ZSB0aGUgYXZlcmFnZSBvZiAzIGV4YW1zIGZvciA1IHN0dWRlbnRzLgovLyBEZXZlbG9wZXI6IEZhY3VsdHkgQ01JUzEwMgovLyBEYXRlOiBKYW4gMzEsIFhYWFgKI2luY2x1ZGUgPHN0ZGlvLmg+CmludCBtYWluICgpCnsKIC8qIHZhcmlhYmxlIGRlZmluaXRpb246ICovCiBjaGFyIFN0dWRlbnROYW1lWzEwMF07CiBmbG9hdCBFeGFtVmFsdWUsIFN1bSwgQXZnOwogaW50IHN0dWRlbnRzLGV4YW1zLCAmbnVtX3ZhbHVlczsKIAogcHJpbnRmKCJIb3cgbWFueSBzdHVkZW50cyB0byBmaW5kIHRoZSBhdmVyYWdlIGZvcj8iKTsKIHNjYW5mKCIlZCIsICZudW1fdmFsdWVzKTsKIAogLy8gTG9vcCB0aHJvdWdoIDUgU3R1ZGVudHMKIGZvciAoc3R1ZGVudHM9MDsgc3R1ZGVudHMgPCAmbnVtX3ZhbHVlcyA7IHN0dWRlbnRzKyspCiB7CiAvLyByZXNldCBTdW0gdG8gMAogU3VtID0wLjA7CiBwcmludGYoIkVudGVyIFN0dWRlbnQgTmFtZSBcbiIpOwogc2NhbmYoIiVzIiwgU3R1ZGVudE5hbWUpOwogLy8gTmVzdGVkIExvb3AgZm9yIEV4YW1zCiBmb3IgKGV4YW1zPTA7IGV4YW1zIDwgMzsgZXhhbXMrKykKIHsKIHByaW50ZiAoIkVudGVyIGV4YW0gZ3JhZGU6IFxuIik7CiBzY2FuZigiJWYiLCAmRXhhbVZhbHVlKTsKIFN1bSArPSBFeGFtVmFsdWU7CiB9CiBBdmcgPSBTdW0vMy4wOwogcHJpbnRmKCAiQXZlcmFnZSBmb3IgJXMgaXMgJWZcbiIsU3R1ZGVudE5hbWUsQXZnKTsKIH0KIHJldHVybiAwOwp9Cg==
compilation info
prog.c: In function 'main':
prog.c:11:22: error: expected identifier or '(' before '&' token
int students,exams, &num_values;
^
prog.c:14:15: error: 'num_values' undeclared (first use in this function)
scanf("%d", &num_values);
^
prog.c:14:15: note: each undeclared identifier is reported only once for each function it appears in
stdout