0

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?

5
Contributors
5
Replies
26
Views
1 Week
Discussion Span
Last Post by Reverend Jim
1

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()

Edited by Jerome_6

0

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");
0

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

Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.