ETH官方钱包

切換
舊版
前往
大廳
主題

C語言:成績輸入統計

查理 | 2013-09-10 21:50:03 | 巴幣 4 | 人氣 1457

#include <stdio.h>

int main()
{
    int grade;
    int aCount = 0;
    int bCount = 0;
    int cCount = 0;
    int dCount = 0;
    int fCount = 0;

    printf("Enter the letter grades.\n");
    printf("Enter the EOF character to end input.\n");

    while((grade = getchar())!= EOF){
        switch(grade){
            case 'A':
            case 'a':
                ++aCount;
                break;
            case 'B':
            case 'b':
                ++bCount;
                break;
            case 'C':
            case 'c':
                ++cCount;
                break;
            case 'D':
            case 'd':
                ++dCount;
                break;
            case 'F':
            case 'f':
                ++fCount;
                break;
            case '\n':
            case '\t':
            case ' ':
                break;

            default:
                printf("Incorrect letter grade entered.");
                printf("Enter a new grade.\n");
                break;
         }
    }

    printf("\nTotals for each letter grade are:\n");
    printf("A: %d\n" ,aCount);
    printf("B: %d\n" ,bCount);
    printf("C: %d\n" ,cCount);
    printf("D: %d\n" ,dCount);
    printf("F: %d\n" ,fCount);

    system("pause");
    return 0;
}

創作回應

更多創作