Grading Program

Need help to input a code for y/n and entering a 0 and also, my code is displaying ,y numbers I input instead of displaying from highest to lowest when I compile it. How do i fix this?

My program calls for:

Program - Arrays

Problem:

Set up a grading program. The program should allow the user to enter grades from the keyboard until a 0 is entered OR 10 grades have been entered. The program should then sort the grades in order of highest to lowest, print the grades in sorted order, and finally print the average grade.

Process:

1. Display a message on the screen asking the user if he/she wants to average grades. If the answer is 'y', allow the user to enter grades until a 0 is entered or 10 grades have been entered.

2. Load the data given into an array for later use.

3. After the user enters a 0 to quit, sort the array from largest to smallest. Average the grades and print the grades in sorted order with the average (precise to 2 decimal places) last:

Allow the process to be repeated until the user enters 'n' to quit.

I need help with the code for the user to enter y/n or a 0 to quit and also to arrange the grade from highest to lowest instead of lowest to highest.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
 #define NUMGRADES 10
int main()
	{
    
	 
	    float grades[NUMGRADES] = {0.0};
	    float total             = 0.0,
	          input             = 0.0,
	          average           = 0.0;
	    int   gradecount        = 0,
	          i                 = 0;

		printf( "Welcome to the automatic grading system:\n ");
		printf( "Do you want to average a student's grade? (y/n)\n ");
	 
	    while (gradecount < NUMGRADES)         
	    {
	        printf ("Enter a grade: ");
	        scanf ("%f", &input);
	        
	        if (input < 0)
	        {
	            break;
	        }
	        else
	        {
	            grades[gradecount] = input;        
	            total += input;
	            gradecount++;
	        }
	    }
	 
	    printf("Grades entered: \n");
	    for (i = 0; i < gradecount; i++)
	    {
	        
	        if (grades[i] < average)
	        {
	            printf("* %5.2f\n", grades[i]);
	        }
	        else
	        {
	            printf(" %6.2f\n", grades[i]);
	        }
	    }
        average = total/gradecount;
	    printf("The average grade is: %.2f\n", average);


	    getchar();
		system("pause");
	    return 0;
	}
 
Topic archived. No new replies allowed.