Hello everyone, I have only been coding for only a few weeks and I am still trying to learn all the basics. I have been tasked with a code that is currently set to average 3 tests for 5 students. I need to allow the code to accept x number of students. Is there away I can modify the "For" loop to complete this or do I need to try a different loop? Attached is the entire code and below it are a few things I've tried change.
---------------------------------------------------------------
Code:
#include <stdio.h>
int main ()
{
/* variable definition: */
char StudentName[100];
float ExamValue, Sum, Avg;
int students,exams;
// Loop through 5 Students
for (students=0; students <5 ; 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");
scanf("%f", &ExamValue);
Sum += ExamValue;
}
Avg = Sum/3.0;
printf( "Average for %s is %f\n",StudentName,Avg);
}
return 0;
}
-------------------------------------------------------
So far I have tried changing:
for (students=0; students <5 ; students++)
into
for (students=0; students <=0 ; students++)
And
int students,exams, MAX;
// Loop through all Students
for (students=0; students <MAX ; students++)
In both scenarios the compiler will run, but not provide averages for any imputed students or test scores.
Any help would be greatly appreciated, Thank you.
Sorry if I'm not very clear or using correct terminology.