You must create a structure student_t to store the student name and the three ex
ID: 3627543 • Letter: Y
Question
You must create a structure student_t to store the student name and the three exam scores. You will create an array of this structure in the main function.Although the exact number of students is not known prior to entry, there will be no more than 50 students in the class. Be sure to INPUT all data into array of structures before any calculations are done.
Output list should be like this:
Enter Name <Ctrl-Z to stop>: John Smith
Enter student's three exams: 70 80 90
Name Exam 1 Exam 2 Exam 3 Average
John Smith 70 80 90 80.0
The class average is :
Press any key to continue...
Explanation / Answer
#include #include void main() { struct student_t { char name[20]; int marks1; int marks2; int marks3; }; struct student_t records[50]; int i = 0; int sum[50]; float average[50]; char choice; int j; for(j = 0; j < 50; j++) { sum[j] = 0; average[j] = 0.0; } do { printf(" Enter the name:"); scanf("%s",&records[i].name); printf(" Enter Marks of Exam 1:"); scanf("%d",&records[i].marks1); printf(" Enter Marks of Exam 2:"); scanf("%d",&records[i].marks2); printf(" Enter Marks of Exam 3:"); scanf("%d",&records[i].marks3); sum[i] = records[i].marks1 + records[i].marks2 + records[i].marks3; average[i] = sum[i]/3.0; printf(" Name : %s",records[i].name); printf(" Exam 1 : %d",records[i].marks1); printf(" Exam 2 : %d",records[i].marks2); printf(" Exam 3 : %d",records[i].marks3); printf(" Average : %f",average[i]); i++; printf(" Do you wish to continue? (y/n)"); scanf("%c",&choice); }while(choice == 'y' || choice == 'Y'); getch(); } ------------------------------------------------------ This program runs perfectly. Hope this helps. All The Best!!! Please do rate me. Thanks.Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.