Answer to Question #208849 in C for senoko

Question #208849

Code a program to get an unknown number of test percentages from the user. Accept percentages until the user enters a percentage of -99. This number ( -99) indicates the end of the data and must not be used as part of the calculations.

 Assign a letter grade based on the test percentage according to the following rules:

TEST PERCENTAGE    GRADE

From 80 to 100  ‘A’

From 70 to 79   ‘B’

From 60 to 69   ‘C’

From 50 to 59  ‘D’

0 - 49          'F'

Display the test percentage and letter grade for the student.

Count how many pass percentages (50 - 100) and fail (0 - 49) percentages, as well as invalid percentages (below zero and above 100), are entered.

  then calculate the average percentage (from the valid percentages entered). Display the average percentage, number of passes, number of fails, and number of invalid percentages.


1
Expert's answer
2021-06-20T08:12:22-0400
#include <stdio.h>


int main()
{
    int value;
    int done=0;
    int sum=0;
    int num_pass=0;
    int num_fail=0;
    int num_valid=0;
    int num_invalid=0;


    do {
        printf("Enter a test percentageЖ ");
        scanf("%d", &value);


        if ( value == -99) {
            done = 1;
        }


        else if (value < 0 || value > 100) {
            num_invalid++;
            sum += value;
            printf("Percetage: %3d invalide value\n", value);
        }
        else if (value >= 80) {
            num_pass++;
            num_valid++;
            sum += value;
            printf("Percentage: %3d Grade: A\n", value);
        }
        else if (value >= 70) {
            num_pass++;
            num_valid++;
            sum += value;
            printf("Percentage: %3d Grade: B\n", value);
        }
        else if (value >= 60) {
            num_pass++;
            num_valid++;
            sum += value;
            printf("Percentage: %3d Grade: C\n", value);
        }
        else if (value >= 50) {
            num_pass++;
            num_valid++;
            sum += value;
            printf("Percentage: %3d Grade: D\n", value);
        }
        else {
            num_fail++;
            num_valid++;
            sum += value;
            printf("Percentage: %3d Grade: F\n", value);
        }
        
    } while (!done);



    if (num_valid > 0) {
        double average;
        average = (double) sum / (double) num_valid;
        printf("Average percantage %f\n", average);
    }
    else {
        printf("No data to calculate average\n");
    }
    printf("Number of passes: %d, number of fails: %d, number of invalid percentages: %d\n", 
            num_pass, num_fail, num_invalid);


    return 0;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS