我正在上课。我不断收到错误消息,看不到我要去哪里。教授说要看书中的例子。我做到了,我的看起来也没什么不同。因此,我尝试在书中输入一个错误,并在同一位置出现相同的错误。我要去哪里错了?

#include <stdio.h>

int main(void)
{
    int nmgrades, i, grade;
    int totgrade = 0;
    float average

    printf("First enter the number of grades to process: ");
    scanf("%i", &nmgrades);

    for (i = 1; i <= nmgrades; ++i) {
        printf(enter grade i%: ", i);
        scanf("%i", %grade);

        totgrade = totgrade + grade;

    }

    average = (float) totgrade / nmgrades;

    printf("Grade average %.2f", average);

    return 0;

}

最佳答案

#include <stdio.h>

int main(void)
{
    int nmgrades, i, grade;
    int totgrade = 0;
    float average; // Forgot semicolon

    printf("First enter the number of grades to process: ");
    scanf("%i", &nmgrades);

    for (i = 1; i <= nmgrades; ++i) {
        //printf(enter grade i%: ", i); // wrong
            printf("enter grade %i: ", i);
        //scanf("%i", %grade);
        scanf("%i", &grade); // Ampersand, not percent


        totgrade = totgrade + grade;

    }

    average = (float)totgrade / nmgrades;

    printf("Grade average %.2f", average);

    return 0;

}

10-06 09:09