I need help with:

*the code for y/n and entering a 0 or 10.
* and how do I switch from lowest to highest to highest to lowest?

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.

    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, 0 to quit: ");
    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;
    }

Recommended Answers

All 3 Replies

Which part(s) of the assignment do you want help with? I see you haven't yet added code to sort the array. There are a lot of sorting algorithms, the simplest one top code is the bubble sort.

I know we are supposed to use a bubble sort. But I am new at this so never used one. Dont even know where to start. I need help with:

*the code for y/n and entering a 0 or 10.
* and how do I switch from lowest to highest to highest to lowest?

and how do I switch from lowest to highest to highest to lowest

Are you talking about the sort order? e.g. switch from ascending to descending order? Study the link I gave you to find out how to code the bubble sort, it even gives you the code for it. One of the lines compares two values, to switch from ascending to descending order all you have to do is change the comparison from > to <.

After the line printf( "Do you want to average a student's grade? (y/n)\n "); you need to add a big if statement to test if 'y' was entered, something like this:

char answer;
printf( "Do you want to average a student's grade? (y/n)\n ");
scanf("%c", &answer);
if( answer == 'Y' )
{
   // put all existing code here

}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.