I have been tasked with making this code allow the user to enter an unspecified amount of student names and avg here 3 test grades. Once that is done I set it to end the loop when a negative number is entered. (atleast that's the plan) When the code is put into the compiler (ideone.com) it runs successfully but there is not output....why?
Code:
#include <stdio.h>
int main ()
{
/* variable definition: */
char StudentName[100];
float ExamValue, Sum, Avg, value;
int students,exams,studentname;
// reset Sum to 0
Sum =0.0;
// Loop through Students
while (students > 0)
{
printf("Enter Student Name \n");
scanf("%s", StudentName);
scanf("%f", &value);
{studentname = studentname + 1; }
if (studentname < 0){
break;
printf("End of Student list");
}
// 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;
}
Comment