With this program its suppose to allow the user to input a persons name and then
ID: 3647049 • Letter: W
Question
With this program its suppose to allow the user to input a persons name and then his/her three test scores. This process is looped-which is shown in the sample output- until the user enters "CTRL-Z". I'm certain I have the gist of the program, it's just I'm running out of time and can't get it to work like the sample output.
-------------------------------------------------------------------
#include<stdio.h>
typedef struct {
char name[60];
float exam[3]; /* 3 exams*/
float avg;
} person_t;
int main()
{
person_t persons[50]; //declare structure variable array- up to 50 people
int i, count = 0; //intitializing counting variable
float avg, sum = 0, sum_v = 0;
while(1) // loop repeats until ctrl-Z is pressed
{
printf(" Enter student name <Ctrl-Z to stop>: ");
scanf("%s",& persons[count].name[i]);
for (i = 0; i < 3; i++)
{
printf("Enter student's three exams: ");
scanf("%d", & persons[count].exam[i]); // Allows user to input the values for three values
sum = sum + persons[count].exam[i]; //summing up the test values
}
persons[count].avg = sum/3; //average of the values entered
printf(" Name Exam 1 Exam 2 Exam 3 Average "); // Should be output in this formatt
printf("%s %f %f %f %.1f ",persons[count].name, persons[count].exam[0],persons[count].exam[1], persons[count].exam[2], persons[count].avg);
sum_v = sum_v +(persons[count].avg);
count++;
}
avg = sum_v/count;
printf(" The class average is %.1f",avg);
system("pause");
return 0;
}
---------------------------------------------------------------------------
-----------------------------------------------------------------------