Read grades and then compute an average test grade - C Data Type

C examples for Data Type:float

Description

Read grades and then compute an average test grade

Demo Code

#include <stdio.h>

int main()/*from  w ww .ja  va 2s  .c  om*/
{
    int numTest;
    float stTest, avg, total = 0.0;

    for (numTest = 0; numTest < 25; numTest++)
    {
        printf("\nWhat is the next student's test score? ");
        scanf(" %f", &stTest);

        if (stTest < 0.0)
        {
            break;
        }

        total += stTest;
    }

    avg = total / numTest;

    printf("\nThe average is %.1f%%.\n", avg);

    return 0;
}

Result


Related Tutorials