Pascal Help

Please support our Pascal and Delphi advertiser: Programming Forums - DaniWeb Sister Site
Reply

Join Date: Apr 2005
Posts: 2
Reputation: l_23 is an unknown quantity at this point 
Solved Threads: 0
l_23 l_23 is offline Offline
Newbie Poster

Pascal Help

 
0
  #1
Apr 12th, 2005
I am supposed to create a Pascal program that obtains 4 inputs from user and averages them. The program should enforce all inputs to be between 0 and 100, inclusive. This is for class, but more importantly I have more programs and I need to understand why I suck at this. Not looking for an easy answer. I appreciate any help.

ERROR messages
pro4.pas(15,20) Warning: Variable NUM does not seem to be initialized
pro4.pas(25) Fatal: Unexpected end of file


PROGRAM pro4(input,output);

VAR

tot, num, i: integer; ave: real;

BEGIN

ave:= tot/4;

for i:= 1 to 4 do begin

writeln (output, 'Enter integer');

readln (input, num + tot);

while(num>=0) and (num<=100) do begin

writeln(output, 'Get another integer');

readln(input, ave);

end ;
Reply With Quote Quick reply to this message  
Join Date: Nov 2004
Posts: 6,143
Reputation: jwenting is just really nice jwenting is just really nice jwenting is just really nice jwenting is just really nice 
Solved Threads: 212
Team Colleague
jwenting's Avatar
jwenting jwenting is offline Offline
duckman

Re: Pascal Help

 
0
  #2
Apr 13th, 2005
readln (input, num + tot); uh...
where's your end. to end the program
As people are clearly allowed to attack me but I'm not allowed to defend myself, I no longer post to this site.
Reply With Quote Quick reply to this message  
Join Date: Jan 2005
Posts: 31
Reputation: Jackrabbit is an unknown quantity at this point 
Solved Threads: 0
Jackrabbit Jackrabbit is offline Offline
Light Poster

Re: Pascal Help

 
0
  #3
Apr 13th, 2005
See comments in code:

Pascal and Delphi Syntax (Toggle Plain Text)
  1. program pro4(input, output);
  2. var
  3. tot, num, i: integer;
  4. ave: real;
  5. begin
  6. ave := tot / 4; { tot hasn't been initialized yet. Can't do this here. }
  7.  
  8. for i := 1 to 4 do
  9. begin
  10. writeln(output, 'Enter integer');
  11. readln(input, num + tot); { You can't perform math operation here. }
  12. {
  13.   The following loop will be keep repeating until the user
  14.   enters a value outside the valid range. I don't think
  15.   that's what you want.
  16.   }
  17. while (num >= 0) and (num <= 100) do
  18. begin
  19. writeln(output, 'Get another integer');
  20. readln(input, ave); { why are you reading into ave? }
  21. end;
  22. end; { for loop } { This was missing. }
  23. end. { program } { This was missing. }

Revised code (compiles with FreePascal / WinXP):

Pascal and Delphi Syntax (Toggle Plain Text)
  1. program Program4;
  2. uses
  3. SysUtils;
  4. var
  5. Total: Integer;
  6. Number: Integer;
  7. I: Integer;
  8. Average: Double;
  9. begin
  10. { Initialize Total to zero. }
  11. Total := 0;
  12.  
  13. { Get four integer values from the user. }
  14. for I := 1 to 4 do
  15. begin
  16. Write('Enter an integer value between 0 and 100 (inclusive): ');
  17. ReadLn(Number);
  18. while (Number < 0) or (Number > 100) do
  19. begin
  20. WriteLn;
  21. WriteLn('Error: Number out of range. Please re-enter.');
  22. WriteLn;
  23. Write('Enter an integer value between 0 and 100 (inclusive): ');
  24. ReadLn(Number);
  25. end;
  26. Total := Total + Number;
  27. end;
  28.  
  29. { Calculate the average. }
  30. Average := Total / 4.0;
  31.  
  32. { Display the average. }
  33. WriteLn;
  34. WriteLn('The average is: ' + FloatToStr(Average));
  35. WriteLn;
  36. end.
Reply With Quote Quick reply to this message  
Join Date: Apr 2005
Posts: 2
Reputation: l_23 is an unknown quantity at this point 
Solved Threads: 0
l_23 l_23 is offline Offline
Newbie Poster

Re: Pascal Help

 
0
  #4
Apr 13th, 2005
Thank you both very much. I managed to put everything together, and met with my professor for a little more understanding. I really appreciate each of you being helpful instead of bashing me for not being smart enough to creat a simple program.
Reply With Quote Quick reply to this message  
Join Date: Oct 2008
Posts: 1
Reputation: Harridi is an unknown quantity at this point 
Solved Threads: 0
Harridi Harridi is offline Offline
Newbie Poster

Re: Pascal Help

 
0
  #5
Oct 26th, 2008
ehh
i'm in coding a go game on pascal. this is the code as far
program IGOPascal;

uses
wincrt;

type
igo=0..3;

var
papan:array[1..15,1..15]of igo;
xt,yt:array[0..225]of integer;
tanda:array[1..4]of boolean;
a,b,x,y,i,j,pin:integer;

procedure cek_d1(xd:integer;yd:integer;pin:integer);
begin
case papan[xd,yd] of
0:exit;
1:cek_c(xd,yd,pin);
2:begin
tanda[j]:=true;
exit;
end;
end;

procedure cek_d2(xd:integer;yd:integer;pin:integer);
begin
case papan[xd,yd] of
0:exit;
2:cek_c(xd,yd,pin);
1:begin
tanda[j]:=true;
exit;
end;
end;
procedure cek_c(xc:integer;yc:integer;pin:integer);

begin
pin:=pin+1;
for j:=1 to 4 do
begin
case j of
2:begin
xt[pin]:=xc+1;
yt[pin]:=yc;
end;

1:begin
xt[pin]:=xc-1;
yt[pin]:=yc;
end;

4:begin
xt[pin]:=xc;
yt[pin]:=yc+1;
end;

3:begin
xt[pin]:=xc;
yt[pin]:=yc-1;
end;
end;
case papan[x,y] of
1:cek_d1(xt[0],xy[0]);
2:cek_d2(xt[0],xy[0]);
end;
end;
if tanda=true then
papan[xc,yc]:=3;
end;

procedure cek_b1(xb:integer;yb:integer);

begin
case papan[xb,yb] of
0:exit;
1:exit;
2:cek_c(xb,yb,0);
end;

procedure cek_b2(xb:integer;yb:integer);

begin
case papan[xb,yb] of
0:exit;
2:exit;
1:cek_c(xb,yb,0);
end;

procedure cek_igo(xa:integer;ya:integer);

begin
for i:=1 to 4 do
begin
case i of
1:begin
xt[0]:=xa+1;
yt[0]:=ya;
end;

2:begin
xt[0]:=xa-1;
yt[0]:=ya;
end;

3:begin
xt[0]:=xa;
yt[0]:=ya+1;
end;

4:begin
xt[0]:=xa;
yt[0]:=ya-1;
end;
end;
case papan[x,y] of
1:cek_b1(xt[0],xy[0]);
2:cek_b2(xt[0],xy[0]);
end;
end;
for i:=1 to 225 do
for j:=1 to 225 do
if papan[j,i]=3 then
papan[j,i]=0;

end;




begin
readln(x);
readln(y);
cek_igo(x,y);
end.


it use a multiple procedure
can someone help me?
Reply With Quote Quick reply to this message  
Join Date: Aug 2008
Posts: 1,735
Reputation: LizR has a spectacular aura about LizR has a spectacular aura about 
Solved Threads: 186
LizR LizR is offline Offline
Posting Virtuoso

Re: Pascal Help

 
0
  #6
Oct 27th, 2008
Make a new thread as the intiial post was answered and this is not your thread. Post with code tags so your code is readable. As well as explain the problem you're having.
Last edited by LizR; Oct 27th, 2008 at 5:51 am.
Did I just hear "You gotta help us, Doc. We've tried nothin' and we're all out of ideas" ? Is this you? Dont let this be you! I will put in as much effort as you seem to.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the Pascal and Delphi Forum


Views: 3845 | Replies: 5
Thread Tools Search this Thread



Tag cloud for Pascal and Delphi
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC