-
Code problem
Code:
/* simply exercise */
#include <stdio.h>
/* function main begins program execution */
int main()
{
int grade /* declare */
printf( "Enter your grade: " );
scanf( "%d", &grade );
if ( grade >= 90 )
printf( "A\n" );
else if ( grade >= 80 )
printf( "B\n" );
else if ( grade >= 70 )
printf( "C\n" );
else
printf( "D\n");
return 0; /* end program successfully */
} /* end function main */
no matter whatever number I enter , it just show A
plz let me know what's the problem .
Thanks
Edit : prolem solved , thanks
-
>scanf( "%d", grade );
Should be
Code:
scanf( "%d", &grade );
scanf requires an address so that it can modify the variable you pass it instead of a copy. And you're missing a semicolon in the declaration:
Code:
int grade /* declare */
But I assume that was a typo when you posted, otherwise it wouldn't compile.