Code:
#include <stdio.h>
main()
{
/* Variable Declarations */
int x = 0, grades[100], maximum, minimum, average, sum, numGrades, temp;
char changed = 'T';
/* Prompt user to enter the number of grades to process */
printf ("Enter the numer of grades to process (0 - 100): ");
scanf ("%i", &numGrades);
/* Check to make sure number of grades entered is between 0 - 100 */
while (numGrades < 0 || numGrades > 100)
{
printf ("*** Invalid number of grades. Please enter 0 - 100. ***\n");
printf ("Enter the numer of grades to process (0 - 100): ");
scanf ("%i", &numGrades);
} /* end while */
/* If user enters 0 grades to be entered, end program */
if (numGrades == 0)
{
return 0;
} /* end if */
/* Set minimum, maximum, and sum values
to default values for correct ouput */
minimum = grades[0];
maximum = grades[0];
sum = 0;
/* Prompt user to enter each grade per number of grades entered
using a for loop to continue through the array */
for (x = 0; x < numGrades; x++)
{
printf ("Enter grade for student #%i: ", x + 1);
scanf ("%i", &grades[x]);
/* Check to make sure each grade is between 0 - 100 */
while (grades[x] < 0 || grades[x] > 100)
{
printf ("*** Invalid grade entered. Please enter 0 - 100. ***\n");
printf ("Enter grade for student #%i: ", x + 1);
scanf ("%i", &grades[x]);
} /* end while */
/* Determine minimum grade by comparing to current
minimum (default set as first grade entered) */
if (grades[x] < minimum)
{
minimum = grades[x];
} /* end if */
/* Determine maximum grade by comparing to current
maximum (default set as first grade entered) */
if (grades[x] > maximum)
{
maximum = grades[x];
} /* end if */
/* Keep track of sum of grades to calculate average later */
sum = sum + grades[x];
} /* end for */
/* Calculate average of grades */
average = sum / numGrades;
/* Display the minimum, maximum, and class average grades */
printf ("\nThe minimum grade is %i\n", minimum);
printf ("The maximum grade is %i\n", maximum);
printf ("The class average is %i\n", average);
/* Start while loop to sort array in ascending order
by keeping track if grades place is changed or not */
while (changed == 'T')
{
changed = 'F';
/* Start for loop to check if grades need to be resorted
if current grade in the array is larger than the next */
for (x = 0; x < numGrades; x++)
{
/* If current grade is larger than the next, swap their places */
if (grades[x] > grades[x + 1])
{
temp = grades[x];
grades[x] = grades[x + 1];
grades[x + 1] = temp;
changed = 'T';
} /* end if */
} /* end for */
} /* end while */
/* Display the grades entered in ascending order */
printf ("The %i Grades entered were:\n", numGrades);
/* Start for loop to show each grade in order */
for (x = 0; x < numGrades; x++)
{
printf ("%i ", grades[x]);
} /* end for */
printf ("\n");
return 0;
} /* end main */
is what ive tried, but it does not do what ive inteded it to do. its supposed to take 10 numbers between 0 and 100 and i need this program to use array called "grades". and the program has to stop after 10, sum and average the grades and then the programs supposed to sum avg and count the grades