Charles Lloyd
Charles Lloyd

Reputation: 13

Undetermined string or character constant in C

I am doing a program for class. I keep getting an error and I can't see where the heck I am going wrong. Prof said to look at the example in the book. So I do, and mine looks no different. So I try and type out the one in the book and get the same error in the same spot. Where am I going wrong?

#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;

}

Upvotes: 1

Views: 428

Answers (1)

Zebrafish
Zebrafish

Reputation: 14252

#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;

}

Upvotes: 1

Related Questions