I'm learning Pascal in school. I've come across a run time error that's been eluding me these past few days. The error message I get is:

ERROR: line 86, access made to undefined variable

I've been searching t'internet for a while trying to find out some help, alas Pascal as not the most documented of programming languages.

Here is my code:

program WerewolfGameClassAssignment (input, output);

var HelpPrompt, ClassNum, ClassNumCorrect : integer;
	HelpResult, ClassInputResult, ClassInputEpicFail : boolean;
	

procedure Welcome;
	begin
		writeln('Welcome to Nanor''s Werewolf Game (Or similar) class assigner!');
		writeln('Would you like some help?');
		writeln('1) Yes!');
		writeln('2) No!');
		readln(HelpPrompt);
		
		case HelpPrompt of
		1 : HelpResult:=True;
		2 : HelpResult:=False;
		otherwise clrscr; writeln('Invalid input, noob!'); writeln; Welcome;
		end;

	end;
	
procedure HelpText;
	begin
		clrscr;
		writeln('Help');
		writeln('Text');
		writeln('Will');
		writeln('Go');
		writeln('Here');
	end;
	
procedure ClassInput;
	begin
		writeln;writeln;
		writeln('Please input how many classes there are?');
		readln(ClassNum);
		clrscr;
	end;
	
procedure ClassInputCorrect;
	begin
		writeln('You have selected ',ClassNum:2,' classes. Is this correct?');
		writeln('1) Yes');
		writeln('2) No');
		readln(ClassNumCorrect);
	
		if ClassNumCorrect = 1 then
			begin
				clrscr;
				ClassInputResult:=True
			end
		else if ClassNumCorrect = 2 then
			begin
				clrscr;
				ClassInputResult:=False
			end
		else
			ClassInputEpicFail:=True
	end;
		







begin
	Welcome;	{Includes help prompt}
	
	if HelpResult = True then
		begin
			HelpText;	{Display help}
			ClassInput	{Ask how many classes}
		end
	else
		begin
			clrscr;
			writeln('Too good for help, then?');
			ClassInput  {How many classses}
		end;
		
	ClassInputCorrect;	{Validation}
	
	while ((ClassInputResult = False) OR (ClassInputEpicFail = True)) do
		begin
			ClassInput;       {repeat}
		    ClassInputCorrect
		end;

	writeln('Continuation text');  {Program doesn't get to here}
		
		
	
		

end.

I'd appreciate it if this could be kept strictly Pascal and the less said about my boolean variables the better. ;)

Recommended Answers

All 10 Replies

well first of all you didnt include uses crt between begin and var and second of all all you have to do is add readln or readkey at the end:

begin
	Welcome;	{Includes help prompt}
	
	if HelpResult = True then
		begin
			HelpText;	{Display help}
			ClassInput	{Ask how many classes}
		end
	else
		begin
			clrscr;
			writeln('Too good for help, then?');
			ClassInput  {How many classses}
		end;
		
	ClassInputCorrect;	{Validation}
	
	while ((ClassInputResult = False) OR (ClassInputEpicFail = True)) do
		begin
			ClassInput;       {repeat}
		    ClassInputCorrect
		end;

	writeln('Continuation text');  {Program doesn't get to here}
 readkey;  {<---- very important}

if you dont include readkey then the program will just close because it doesnt know to stop so that the user can read.

Missing command.!.. :)

{used units}
Uses Crt;{this module is missing from your program} 
{and before main 'End.' Write a simple command}
{like ReadKey; or ReadLn; and then you will see}
{that:                          }
{'writeln('Continuation text');'}
{'cause I've seen}

I'm not clear as to where I put the 'Uses Crt;' statement. Do I put it before my procedures just after the program line?

put it here:

program WerewolfGameClassAssignment (input, output);

Uses Crt;    {over here!}

var HelpPrompt, ClassNum, ClassNumCorrect : integer;
	HelpResult, ClassInputResult, ClassInputEpicFail : boolean;

See the pascal snippets I wrote a skeleton :)

I'm getting a compilation error when I try to put it there.

ERROR: (3,1): begin expected.
WARNING: (1,38): variable 'input' is never used.
WARNING: (1,45): variable 'output' is never used.

Here's the code in case I've messed something up.

program WerewolfGameClassAssignment (input, output);

Uses Crt;

var HelpPrompt, ClassNum, ClassNumCorrect : integer;
	HelpResult, ClassInputResult, ClassInputEpicFail : boolean;
	



procedure Welcome;
	begin
		writeln('Welcome to Nanor''s Werewolf Game (Or similar) class assigner!');
		writeln('Would you like some help?');
		writeln('1) Yes!');
		writeln('2) No!');
		readln(HelpPrompt);
		
		case HelpPrompt of
		1 : HelpResult:=True;
		2 : HelpResult:=False;
		otherwise clrscr; writeln('Invalid input, noob!'); writeln; Welcome;
		end;

	end;
	
procedure HelpText;
	begin
		clrscr;
		writeln('Help');
		writeln('Text');
		writeln('Will');
		writeln('Go');
		writeln('Here');
	end;
	
procedure ClassInput;
	begin
		writeln;writeln;
		writeln('Please input how many classes there are?');
		readln(ClassNum);
		clrscr;
	end;
	
procedure ClassInputCorrect;
	begin
		writeln('You have selected ',ClassNum:2,' classes. Is this correct?');
		writeln('1) Yes');
		writeln('2) No');
		readln(ClassNumCorrect);
	
		if ClassNumCorrect = 1 then
			begin
				clrscr;
				ClassInputResult:=True
			end
		else if ClassNumCorrect = 2 then
			begin
				clrscr;
				ClassInputResult:=False
			end
		else
			ClassInputEpicFail:=True
	end;
		







begin
	Welcome;	{Includes help prompt}
	
	if HelpResult = True then
		begin
			HelpText;	{Display help}
			ClassInput	{Ask how many classes}
		end
	else
		begin
			clrscr;
			writeln('Too good for help, then?');
			ClassInput  {How many classses}
		end;
		
	ClassInputCorrect;	{Validation}
	
	while ((ClassInputResult = False) OR (ClassInputEpicFail = True)) do
		begin
			ClassInput;       {repeat}
		    ClassInputCorrect
		end;

	writeln('Continuation text');  {Program doesn't get to here}
	
	readln;	
end.

I try your program and nothing went badly....
If you need a good pascal compiler click down link

Dev-Pascal 1.9.2 + Free Pascal compiler :

http://www.bloodshed.net/devpascal.html


This is the Dev-Pascal everything knows that have to

Thanks. I was looking for a decent compiler. I'm using Irie Pascal which the school gave to me. It's a piece of crap! :)

Problem solved! If I may ask, however, what does Uses Crt; do?

uses crt tells the computer that the program is using more than the normal commands and it 'unlocks' so to speak extra features. for instance clrscr wont work without it. you can use others like graph and dos. as far as i know anyway

Ah, that's cool.

I wonder why it doesn't work on my other compiler.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.