Question: Modify the grade book code so that it uses heap memory to store percentage grades in the range from 0 to 100 (inclusive). The program
Modify the grade book code so that it uses heap memory to store percentage grades in the range from 0 to 100 (inclusive). The program should allow the user to indicate when he or she is done entering grades (since the user may not have grades to fill the whole array). When the user is done entering grades, the program should print out the grades entered by the user. Be sure to free the head memory before the program ends. The code is as follows:
#include
int main() { char choice; int percentArray[50]; int percentage; int count=0,i;
for(count=0; count<50; count++) { //for loop to read the grades till array size printf("-------------------Enter percentage--------------- Add marks(a) Quit(q) "); scanf("%c",&choice); if(choice == 'a') { //if user choice is a, then read the grade printf( "Enter grade:"); scanf("%d", &percentage); percentArray[count] = percentage; //add the grade to array } if(choice == 'q') //if the user choice is q, then exit the loop { break; } } printf("Grades are: "); for(i=0; i
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
