--- On Thu, 9/24/09, Kevan Hashemi hashemi@brandeis.edu wrote:
Your code does not compile:
Sorry about that. I was making some last minute changes to it and forgot to revert them before sending it. Here's the correct one which exhibits the behavior, and _does_ compile ;)
Note that I'm compiling it with --classic-pascal because I want to have the correct (ISO) behavior when a newline is not present in the file prior to the EOF. But the problem exists even without this option.
To compile I'm using:
$gpc --classic-pascal grades.pas -o grades
To run: echo -n "20 30 40" | ./grades
Here's the code:
PROGRAM GRADES (INPUT,OUTPUT);
VAR SUM, COUNT, GRADE : INTEGER;
BEGIN SUM := 0; COUNT := 0;
WRITELN('ENTER GRADES AND PRESS CTRL-D WHEN FINISHED'); READ(GRADE);
WHILE NOT EOF DO BEGIN SUM := SUM + GRADE; COUNT := COUNT + 1;
WHILE EOLN DO BEGIN WRITELN('EOLN? ', EOLN); WRITELN('EOF? ', EOF); READLN; END;
IF NOT EOF THEN READ(GRADE); END;
WRITELN('TOTAL STUDENTS ', COUNT); WRITELN('CLASS AVERAGE ', SUM DIV COUNT); END.