Write a C program to implement the following function"

print A for exam grades greater than or equal to 90, B for grades greater than or equal to 80 (but less than 90), C for grades greater than or equal to 70 (but less than 80), D for grades greater than or equal to 60 (but less than 70) and F for all other grades.

Here's what I've done:

include <stdio.h>

int main()
int grade;

if ( grade >= 90 ) {
    printf( "A\n");
}  // end if

else {
    if ( grade >= 80 ) {
    printf( "B\n");
}// end else
}

else {
    if ( grade >= 70 ) {
    printf( "C\n");
     } //end else
}

else {
    if ( grade >= 60 ) {
    printf( "D\n");
     } //end else
}

else {
    printf("F\n");
}

WHAT'S WRONG?

Recommended Answers

All 5 Replies

Your if/else statements don't seem to match.

try

if ()
else if()
else if()
else if()

all you have are empty else statements not else if......as your if are buried in the else blocks

simply remove the curly brackets in the else statements and your done

then....

else()

Your end else comments show where you going wrong... they are all one line above the actual bracket that end the else

the software says that my "int grade" and "scanf" lines have errors, how do i fix it?

include <stdio.h>

int main()
int grade;
scanf("%d\n",&grade)

if ( grade >= 90 ) {
    printf( "A\n");
} // end if

else if ( grade >= 80 ) {
    printf( "B\n");
}// end else

else if ( grade >= 70 ) {
    printf( "C\n");
     } //end else

else
    if ( grade >= 60 ) {
    printf( "D\n");
     } //end else

else
    {printf("F\n");

A tip for future posts - if you are getting errors then post the error messages (and the lines that are causing the errors).

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.