【发布时间】:2015-10-10 23:56:08
【问题描述】:
var
RegNo: array of string;
Speed: array of real;
cars : integer;
time : real;
begin
Setlength(RegNo, 99);
Setlength(Speed, 99);
Writeln ('The speed limit is 50km/h');
Writeln ('The distance between the two points is 50m');
cars := 0;
time := 1;
while time>0
do
begin
cars := cars + 1;
Writeln ('Enter the car takes to pass the two points');
Readln (time);
if time = 0 then
Writeln
else
if time < 1 then
begin
Writeln ('Enter the registration plate for the car');
Readln (RegNo[cars]);
Speed[cars]:= 50/time;
end
else
end;
Setlength (RegNo, cars);
Setlength (Speed, cars);
Writeln (RegNo[cars]);
Writeln (Speed[cars]:5:2);
Readln;
end.
我不明白我做错了什么。这应该是一个程序来读取使用数组加速的汽车。它表示变量RegNo 可能尚未初始化。它表示变量Speed 可能尚未初始化。
【问题讨论】:
-
动态数组使用从零开始的索引。您阅读超出数组末尾的内容。启用范围检查以帮助发现错误。