943,777 Members | Top Members by Rank

Ad:
Jun 24th, 2009
0

runtime error 2

Expand Post »
I am writing a program for a college assignment to compute grades of students. the code compiles ok, but i keep getting a runtime error 2. can anyone help?






Pascal and Delphi Syntax (Toggle Plain Text)
  1. {Author: George Brandon Miller}
  2. {Program: Grade Report - Compute the grade point average for students}
  3. Program Grades;
  4.  
  5. var
  6.  
  7.  
  8. { misc. program variables }
  9.  
  10. more_records:boolean; {end of file flag }
  11. line_count:integer; {lines written count}
  12. page_no:integer; {page count}
  13.  
  14.  
  15. {Student Variables}
  16. FileIn:typedfile; {Input File Handle}
  17. FileOut:text; {Output File Handle}
  18. SECTION_NUMBER:string[5]; {Section number of the class}
  19. STUDENT_ID:string[9]; {Student identification number}
  20. LAST_NAME:string[20]; {Students last name}
  21. FIRST_NAME:string[10]; {Students first name}
  22. RAW_SCORE:real; {Points totaled by the student}
  23. STUDENT_COUNT:integer; {total number of students}
  24. AVERAGE_SCORE:integer; {Average score for all the students}
  25. AVERAGE_GRADE:integer; {Grade for the student}
  26. PERCENT:real;
  27.  
  28. procedure read_record;
  29. begin
  30. if not Eof(fileIn) then
  31. readln(SECTION_NUMBER,STUDENT_ID,LAST_NAME,FIRST_NAME,RAW_SCORE)
  32. else
  33. more_records := False
  34. end; {read record}
  35.  
  36. procedure print_header; {print header at top of page}
  37.  
  38. begin
  39.  
  40. writeln(FileOut,space(14),'CIS150 GRADE REPORT',space(8),page_no);
  41. writeln(FileOut,space(17),'SECTION','SECTION_NUMBER');
  42. Writeln(FileOut);
  43. writeln(FileOut,space(9),'LAST',space(11),'FIRST',' RAW',' COMPUTED');
  44. writeln(FileOut,space(9),'NAME',space(11),'NAME',' SCORE',' GRADE');
  45. Writeln(FileOut);
  46. Writeln(FileOut);
  47. Writeln(FileOut);
  48. Writeln(FileOut);
  49. Writeln(FileOut,'STUDENT COUNT',STUDENT_COUNT);
  50. Writeln(FileOut,'AVERAGE SCORE',AVERAGE_SCORE);
  51. Writeln(FileOut,'AVERAGE GRADE',AVERAGE_GRADE);
  52.  
  53. end;
  54.  
  55. {INITIALIZE - open files and print header}
  56.  
  57. procedure initialize;
  58.  
  59. begin
  60.  
  61.  
  62. assign(fileIn,'C:\Users\Owner\Classes\CIS 150\Data\PRG3-150.DAT');
  63. reset(fileIn);
  64. assign(Fileout,'C:\Users\Owner\Classes\CIS 150\Data\grades.rpt');
  65. rewrite(fileout);
  66.  
  67. read_record;
  68.  
  69. print_header
  70.  
  71. end;
  72.  
  73. procedure process;
  74.  
  75. begin
  76.  
  77. {skip to new page if needed}
  78. Inc(line_count);
  79. if line_count > 50 then
  80. Print_header;
  81.  
  82. percent := (Raw_Score / 850.0) * 100.0;
  83. writeln(FileOut,Last_Name,Space(2),First_Name,Space(3),percent);
  84. read_record;
  85.  
  86. end;
  87.  
  88.  
  89. procedure wrapup;
  90.  
  91. begin
  92. writeln(FileOut);
  93. writeln(FileOut,'Student_Count');
  94. Close(FileIn);
  95. Close(FileOut);
  96. end;
  97.  
  98.  
  99. begin
  100. initialize;
  101.  
  102.  
  103. while more_records do
  104. process;
  105.  
  106.  
  107. wrapup
  108.  
  109. end.
Last edited by Ancient Dragon; Jun 25th, 2009 at 7:14 am. Reason: add code tags
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
mauimaui346 is offline Offline
3 posts
since Jun 2009
Jun 24th, 2009
0

Re: runtime error 2

I changed the filein:filetype; to fileIn:file; and now i get a runtime error 106...im completely lost...any help?
Reputation Points: 10
Solved Threads: 0
Newbie Poster
mauimaui346 is offline Offline
3 posts
since Jun 2009
Jun 25th, 2009
0

Re: runtime error 2

Is this a compiler error message?
Then 2:Identifier expected,106:Character expression expected
Reputation Points: 132
Solved Threads: 138
Posting Pro
FlamingClaw is offline Offline
559 posts
since Feb 2009
Jun 29th, 2009
0

Re: runtime error 2

Is this a compiler error message?
Then 2:Identifier expected,106:Character expression expected
Yes it is a compiler message. and i changed the file. but im still lost.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
mauimaui346 is offline Offline
3 posts
since Jun 2009
Jun 29th, 2009
0

Re: runtime error 2

ok,calm down a bit....now we know where the problem is,right..?...
run your program and look at the line where stops the program
and please paste that line,cause I can't run your program because of missing files...I hope that you understand what I'm talking about....

Error 2: Identifier expected.

I found this error when reading your code
procedure read_record;
begin
if not Eof(fileIn) then
readln(fileIn,SECTION_NUMBER,STUDENT_ID,LAST_NAME,FIRST_NAME,RAW_SCORE)
else
more_records := False
end;
Last edited by FlamingClaw; Jun 29th, 2009 at 6:30 pm.
Reputation Points: 132
Solved Threads: 138
Posting Pro
FlamingClaw is offline Offline
559 posts
since Feb 2009
Jun 30th, 2009
0

Re: runtime error 2

By the way when I looking your code a bit closer I can't find any records ...why???
Create a new type 'something = record',got it?
I made a skeleton
pascal Syntax (Toggle Plain Text)
  1. Program Solution;
  2.  
  3.  
  4. {new type for a student,it contains the data of a student}
  5. Type Stdnt = Record
  6. SECTION_NUMBER:string[5];
  7. STUDENT_ID:string[9];
  8. LAST_NAME:string[20];
  9. FIRST_NAME:string[10];
  10. RAW_SCORE:real;
  11. End;
  12. Var FileIn:File of Stdnt;{declares a file that contains only records}
  13. OneStudent:Stdnt; {one record}
  14.  
  15.  
  16. Procedure read_record;
  17. Begin
  18. If Not EoF(FileIn) Then Readln(FileIn,OneStudent)
  19. Else
  20. more_records := False
  21. End; {read record}
  22. {
  23. After calling this procedure,the OneStudent record is filled
  24. with data like : just example....
  25. OneStudent.SECTION_NUMBER := '12';
  26. OneStudent.STUDENT_ID :='3';
  27. OneStudent.LAST_NAME := 'Joe';
  28. OneStudent.FIRST_NAME := 'Smith';
  29. OneStudent.RAW_SCORE := 12.32;
  30. and you have to work with the OneStudent record
  31. }
  32.  
  33.  
  34. Begin {main}
  35.  
  36.  
  37. ReadLn;
  38. End.
Reputation Points: 132
Solved Threads: 138
Posting Pro
FlamingClaw is offline Offline
559 posts
since Feb 2009

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Pascal and Delphi Forum Timeline: Delphi_rectangle drawing
Next Thread in Pascal and Delphi Forum Timeline: using C# dlls in delphi





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC