I am the new in pascal and i get some problems on my programme.Please read my programme and help to solve it,thanks.
program air_traffic_control;
uses Dos,Crt;
type
airport_platform=record
airplane_no:string[30];
airplane_predicted_time_left:integer;
end;
airtraffic_condition=record
airplane_no:string[30];
airplane_landing_time_left:integer;
end;
var
hour,min,sec,msec:word;
num,target,count,count2,counter,z,a,q:integer;
platformfile,airtrafficfile:text;
platform:array[1..30] of airport_platform;
airtraffic:array[1..20] of airtraffic_condition;
ch:char;
procedure user_display;
type DayType=(Sun,Mon,Tue,Wed,Thu,Fri,Sat);
var
YY,MM,DD,DayOfWeek,hour,min,sec,msec:word;
today:DayType;
password:string[20];
begin
textbackground(black);
ClrScr;
Getdate(YY,MM,DD,DayOfWeek);
GetTime(hour,min,sec,msec);
Today:=DayType(DayOfWeek);
textcolor(yellow);
writeln('Welcome to execute air traffic control');
repeat
textcolor(yellow);
write('Password:');
readln(password);
if password<>'aed7689'
then writeln('Wrong password,enter again');
until password='aed7689';
ClrScr;
writeln('Day of Today:',DD,'/',MM,'/',YY,',',Today);
writeln('Current time: ',hour,':',min,':',sec);
writeln('Now start the system of air traffic control management');
repeat
textcolor(yellow);
write('Enter password again to continue:');
readln(password);
if password<>'aed7689'
then writeln('Wrong password,enter again');
until password='aed7689';
ClrScr;
end;
procedure input_airtraffic(var count2:integer);
var count,x:integer;
begin
for x:=1 to 30 do
airtraffic[x].airplane_no:='';
count2:=0;
assign(airtrafficfile,'C:/airtrafficcontrol/airtraffic.txt');
reset(airtrafficfile);
while not eof(airtrafficfile) do
begin
count2:=count2+1;
with airtraffic[count2] do
begin
readln(airtrafficfile,airplane_no);
readln(airtrafficfile,airplane_landing_time_left);
end;
end;
close(airtrafficfile);
end;
procedure input_platform_condition(var num:integer);
var x,counter:integer;
begin
num:=0;
for x:=1 to 30 do
platform[x].airplane_no:='';
assign(platformfile,'C:/airtrafficcontrol/airport_condition.txt');
reset(platformfile);
counter:=0;
while counter<30 do
begin
counter:=counter+1;
with platform[num] do
begin
readln(platformfile,airplane_no);
readln(platformfile,airplane_predicted_time_left);
if airplane_no<>'$$$'
then num:=num+1;
end;
end;
close(platformfile);
end;
procedure take_off(var num,target:integer);
var choice:char;
password:string[30];
begin
with platform[target] do
begin
repeat
write('plane ',airplane_no,'is ready to take off,asking for permission(Y/N)?');
readln(choice);
if not(choice in ['Y','y','N','n'])
then write('Wrong input choice,please input choice again(Y/N):');
ClrScr;
until (choice='y') or (choice='Y') or (choice='N') or (choice='n');
if (choice='N') or (choice='n')
then airplane_predicted_time_left:=5
else begin
repeat
write('Enter password to execute this order:');
readln(password);
ClrScr;
until password='aed7689';
writeln('please wait for the processing of taking off.......');
delay(20000);
writeln('plane ',airplane_no,'has been taken off');
readln;
num:=num-1;
airplane_no:='$$$';
airplane_predicted_time_left:=999;
end;
end;
end;
procedure update_platform_time_left(var num,target,count:integer);
begin
target:=0;
if count<=30
then
begin
count:=count+1;
with platform[count] do
begin
airplane_predicted_time_left:=airplane_predicted_time_left-1;
if (airplane_predicted_time_left<=0) and (airplane_no<>'')
then begin
target:=count;
if platform[target].airplane_no<>'$$$'
then take_off(num,target);
if count<31
then update_platform_time_left(num,target,count);
end
else if count<30 then
update_platform_time_left(num,target,count);
end;
end;
end;
procedure update_air_traffic(count:integer;var num,count2:integer);
var choice1:char;
target,count1,x,y,n:integer;
password:string[10];
begin
n:=1;
target:=0;
count1:=0;
count:=count+1;
if count<=count2
then begin
with airtraffic[count] do
begin
airplane_landing_time_left:=airplane_landing_time_left-1;
if (airplane_landing_time_left<=0) and (airplane_no<>'')
then begin
repeat
write('airplane ',airplane_no,' is asking for the permission of landing(Y/N):');
readln(choice1);
until (choice1='y') or (choice1='Y') or (choice1='n') or (choice1='N');
repeat
write('Please input password to continue:');
readln(password);
ClrScr;
until password='aed7689';
case choice1 of
'y','Y':begin
while target=0 do
begin
count1:=count1+1;
if count1>30
then exit;
if platform[count1].airplane_no='$$$'
then target:=count1;
end;
if count1>30
then begin
writeln('No platform remain, please stay on the air');
airplane_landing_time_left:=5;
end
else begin
write('airplane ',airplane_no, ' landing to platform ',target);
readln;
platform[target].airplane_no:=airplane_no;
platform[target].airplane_predicted_time_left:=400;
airplane_no:='';
num:=num+1;
for n:=1 to (count2-1) do
begin
if airtraffic[n].airplane_no<>''
then begin
airtraffic[n].airplane_landing_time_left:=airtraffic[n].airplane_landing_time_left;
end;
end;
end;
count2:=count2-1;
end;
'n','N':airplane_landing_time_left:=5
end
end
else if count<31
then begin
update_air_traffic(count,num,count2);
end;
end;
end;
end;
procedure generate_airplane_no(var count2:integer);
var x:array[1..3] of char;
y:array[1..7] of char;
z:string[30];
count,abc:integer;
begin
if count2<30
then begin
count2:=count2+1;
for count:=1 to 3 do
x[count]:=' ';
for count:=1 to 7 do
y[count]:=' ';
if count2<21
then begin
randomize;
abc:=random(9);
for count:=1 to 3 do
x[count]:=chr(random(26)+65);
for count:=1 to 7 do
y[count]:=chr(random(10)+48);
for count:=1 to 2 do
z:=concat(z,x[count]);
for count:=1 to 7 do
z:=concat(z,y[count]);
with airtraffic[count2] do
begin
airplane_no:=z;
airplane_landing_time_left:=random(20)+1;
readln;
end;
end;
end;
end;
procedure update_platformfile;
var n:integer;
begin
rewrite(platformfile);
for n:=1 to 30 do
begin
with platform[n] do
begin
writeln(platformfile,airplane_no);
writeln(platformfile,airplane_predicted_time_left);
end;
end;
close(platformfile);
end;
procedure update_airtrafficfile(var count2:integer);
var n:integer;
begin
rewrite(airtrafficfile);
for n:=1 to count2 do
begin
with airtraffic[n] do
begin
writeln(airtrafficfile,airplane_no);
writeln(airtrafficfile,airplane_landing_time_left);
end;
end;
close(airtrafficfile);
end;
begin
count2:=0;
user_display;
input_airtraffic(count2);
input_platform_condition(num);
while num>=0 do
begin
ClrScr;
GetTime(hour,min,sec,msec);
writeln('Current time: ',hour,':',min,':',sec);
z:=0;
writeln('There are total ',num,' planes in the airport now');
writeln('There are total ',count2,' planes are waiting for landing');
count:=0;
repeat
writeln('Press Enter to continue/Press ESC to exit');
ch:=ReadKey;
ClrScr;
until (ch=#27) or (ch=#13);
case ch of
#13:begin
if (num=0) and (count2=0)
then begin
writeln('No plane information found, please wait until plane land/take off....');
writeln('press ENTER to continue!!');
repeat
ch:=ReadKey;
until (ch=#13);
ClrScr;
end;
if (num<>0) and (count2<>0)
then begin
generate_airplane_no(count2);
ClrScr;
writeln('Waiting for the system instruction.....');
delay(10000);
ClrScr;
update_air_traffic(count,num,count2);
update_platform_time_left(num,target,count);
update_platformfile;
update_airtrafficfile(count2);
end;
end;
#27:exit;
end;
end;
end.
here is my code and after executing many procedures , i try to save my record and update my textfile.However i stuck on my saving of update_platformfile. the data saved is out of my expectation.
what i want is:
$$$
999
ays5598745
4
afj7895542
11
asw7865456
17
afu7641313
22
hfi7646411
29
dai5641321
40
ash7646132
49
ash4564653
58
kjs8463133
63
kja7645413
69
ahf4613133
74
sad8976463
81
qwr2131852
88
hdf1341679
93
djd7641232
98
qwr7841321
101
dsa7643125
110
fdd4632154
116
thr5412312
121
vxj7643135
125
jhd6734535
131
rjn8764354
138
fds8645643
141
her7634351
150
hbg5643515
153
ery4123156
160
few3131548
166
$$$
999
$$$
999
however after updated i got
afj7895542
4
asw7865456
10
afu7641313
15
hfi7646411
22
dai5641321
33
ash7646132
42
ash4564653
51
kjs8463133
56
kja7645413
62
ahf4613133
67
sad8976463
74
qwr2131852
81
hdf1341679
86
djd7641232
91
qwr7841321
94
dsa7643125
103
fdd4632154
109
thr5412312
114
vxj7643135
118
jhd6734535
124
rjn8764354
131
fds8645643
134
her7634351
143
hbg5643515
146
ery4123156
153
few3131548
159
HK6206933
393
-7
-7
-7
i am sorry that it costs a lot of time of teaching a novice but
Could you help to figure out what i get wrong on my programme or on my logic,please?