Directions Modify the grade book code so that it uses custom

Directions: Modify the grade book code so that it uses custom functions to add grades to the array, print the grades entered, calculate the average grade (arithmetic mean, not letter grade), and report the highest and lowest grade entered. This version of the program does not need to use heap memory, though you are welcome to do so. 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. The program should also display the average grade, highest grade, and lowest grade.

Here is the current code:

#include <stdio.h>
#include <conio.h>
#include <stdlib.h>


int main()
{
#define INT_MAX 100;
#define INT_MIN 34;

char choice;
const int SIZE=5;
int percentArray[5];
int percentage;
int count=0,i;
double total=0;
double avg=0;
int low,high;

//Set MAX TO low
low=INT_MAX;
//Set MIN TO high
high=INT_MIN;

for(count=0; 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

//sum of percentArray values
total+=percentArray[count];

//update low
if(percentArray[count] low=percentArray[count];

//update high
if(percentArray[count]>high)
high=percentArray[count];
count++;


}
if(choice == \'q\') //if choice is q, exit the loop
{
break;
}
//clear buffer
fflush(stdin);
}
printf(\"Grades are: \");
for(i=0; i {
//print grades
printf(\"%d \", percentArray[i]);
}

//print average ,low and high vlaues to console
printf(\"\ Average : %5.2f\ \",total/count);
printf(\"Lower Grade : %5d\ \",low);
printf(\"Higher Grade : %5d\ \",high);

getch();
return 0;

}

My question is, how can I modify the current code without using #include <conio.h>, as using this is not standard.

Solution

#include <stdio.h>
#define INT_MAX 100;
#define INT_MIN 34;
#include <stdlib.h>


double Getavg(int percentArray[])
{
   float sum=0;
int i;
   for ( i = 0; i < 5; ++i)
   {
       sum+=percentArray[i];
   }

   return sum/5;
}

int GetLow(int percentArray[])
{
int low=INT_MAX;
int count;
       for(count=0; count<5;count++)
       {
       //update low
       if(percentArray[count] <low)
           low=percentArray[count];
       }

return low;
}

int GetHigh(int percentArray[])
{
       int high=INT_MIN;;
       int count;
               for(count=0; count<5;count++)
               {
               //update low
               if(percentArray[count] >high)
                   high=percentArray[count];
               }

return high;
}
int main()
{

char choice;
const int SIZE=5;
int percentArray[5];
int percentage;
int count=0,i;
double total=0;
double avg=0;

for(count=0; count<5;)
{ //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
           //sum of percentArray values
      
count++;

}
if(choice == \'q\') //if choice is q, exit the loop
{
break;
}

}
printf(\"Grades are: \");
for(i=0; i<5;i++)
{
//print grades
printf(\"%d \", percentArray[i]);
}
//print average ,low and high vlaues to console
printf(\"\ Average : %5.2f\ \",Getavg(percentArray));
printf(\"Lower Grade : %5d\ \",GetLow(percentArray));
printf(\"Higher Grade : %5d\ \",GetHigh(percentArray));

return 0;
}

=====================================================

Output:

akshay@akshay-Inspiron-3537:~/Chegg$ gcc grade.c
akshay@akshay-Inspiron-3537:~/Chegg$ ./a.out
-------------------Enter percentage---------------
Add marks(a)
Quit(q)
a
Enter grade:10
-------------------Enter percentage---------------
Add marks(a)
Quit(q)
-------------------Enter percentage---------------
Add marks(a)
Quit(q)
a
Enter grade:20
-------------------Enter percentage---------------
Add marks(a)
Quit(q)
-------------------Enter percentage---------------
Add marks(a)
Quit(q)
a
Enter grade:30
-------------------Enter percentage---------------
Add marks(a)
Quit(q)
-------------------Enter percentage---------------
Add marks(a)
Quit(q)
a
Enter grade:40
-------------------Enter percentage---------------
Add marks(a)
Quit(q)
-------------------Enter percentage---------------
Add marks(a)
Quit(q)
a
Enter grade:50
Grades are: 10 20 30 40 50
Average : 30.00
Lower Grade : 10
Higher Grade : 50

Directions: Modify the grade book code so that it uses custom functions to add grades to the array, print the grades entered, calculate the average grade (arith
Directions: Modify the grade book code so that it uses custom functions to add grades to the array, print the grades entered, calculate the average grade (arith
Directions: Modify the grade book code so that it uses custom functions to add grades to the array, print the grades entered, calculate the average grade (arith
Directions: Modify the grade book code so that it uses custom functions to add grades to the array, print the grades entered, calculate the average grade (arith

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site