To help debug your problem, consider the code example
at the end of this article.
http://linux.die.net/man/3/scanf
"Return Value
These functions return the number of input items successfully
matched and assigned, which can be fewer than provided for,
or even zero in the event of an early matching failure."
The author of the code segment at the end of the article,
checks the returned value from scanf. If scanf didn't find
a valid input, then there's no reason to store a new value
in "grade". The old value might still be stored in there.
You might want to analyze what is coming back from scanf,
to understand what might be happening.
Defensive programming might seem like a chore, but
it pays off dividends later. If scanf returns a value,
and there is a way for scanf to screw up, you should
be checking for that condition.
In fact, as a rank amateur at C programming myself, if
I don't know how a function works, I may test it
first. I write a separate test program, to test my
understanding of how it works.
/* insert usual program constructs as necessary... */
/* this is a snippet */
int n;
int grade = 79;
n = scanf("%d",&grade);
printf("I got %d back from scanf, and %d is my grade\n", n, grade);
Then, I try some test values, 23, -1, invalid_string,
and so on, and for each test program run, see what happens
with respect to input. If I see a value of 79 printed for grade,
then I suspect no assignment to grade had been made.
Input is tricky, and you can easily spend more time making
the program robust against command line arguments, or input
formatting, than in the actual program logic.
You might also end up testing for differences, between
feeding the program from a file, rather than interactive
input from stdin.
grade_program < list_of_grades_file.txt > output_of_my_program.txt
I have no idea why your program is broken, but seeing
as you're not checking the returned value of scanf,
that's where I'd start to make changes.
HTH,
Paul