Question: Here are the directions: Modify you grade book program to use a custom struct to hold the student's ID number and the percentage score for
Here are the directions:
Modify you grade book program to use a custom struct to hold the student's ID number and the percentage score for each item in the grade book. The program should accept the entry of ID numbers and percentage grades (0100) until the user signals that he or she is done entering grades. The program should then print out the ID numbers and grades entered by the user, sorted by ID number.
Here is the code:
#include
int main() { //variables char choice; int count,i,j; int n; int temp; for(count=0; count<50; count++) { //loop to read the grades till array size printf("-------------------sorting --------------- Sorting(s) Quit(q) "); scanf("%c",&choice); if(choice == 's') { //if user choice is s, then read the id number and percentage printf( "Enter id number"); scanf("%d", &s[count].stuid); printf( "Enter grade:"); scanf("%d", &s[count].per); //while loop for entering valid score while(s[count].per>=0 && s[count].per<=100) { printf( "please enter a valid score between 0 to 100"); scanf("%d", &s[count].per); } } if(choice == 'q') //if the user choice is q, then exit the loop { break; } } n=count; //sorting struct based on student id number for (i = 1; i < n; i++) for (j = 0; j < n - i; j++) { if(s[j].stuid> s[j+1].stuid) { temp = s[j].stuid; s[j].stuid = s[j+1].stuid; s[j+1].stuid = temp; }
printf("student id and average scores are: "); for(i=0; i I am having problems with this code. The grade book compiles, but it does not run correctly. I dont think the program's printed instructions for the user are clear about the program should be used. However, I do know the code has a properly defined struct to use for each grade entry. Even after the user enters a score with the valid range, the program prompts the user again to enter the grade, it continues to prompt for grades without asking again for an ID number. I know the program should be set up so that it asks for an ID number and then the score for each entry but Im not sure how to do that. I also dont think the loops are not set up correctly for the sort, so the program does not produce sorted output. Please help.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
