我遇到了这个程序的问题。该项目是收银机。
Program Cash_Register;
var
ItemsPrices: array[1..20] of real;
ItemsNames: array[1..20] of string;
Item_Number: integer;
NameNumber: integer;
PriceTracker: integer; {1}
NameTracker: integer; {1}
To_End_Or_Not_To_End: string;
PriceNumber: integer; {0}
Subtotal: real;
gst_sum: real;
Final_Total: real;
const
GST: real = 0.125; {0.125}
Base: integer = 21; {21}
CR: string = #13; {#13}
LF: string = #10; {#10}
CRLF: string = #13#10; {CR + LF}
begin
{Variable and constant assignment}
PriceTracker:= 1;
NameTracker:= 1;
PriceNumber:= 0;
{This area below starts the name taking and price taking}
while (PriceTracker AND NameTracker) < Base do
begin
{This area below Asks the user for the name of the product}
Writeln('Please enter the name of product ');
write(Item_Number);
write(' please.');
readln(ItemsNames[Item_Number]);
{This area below asks the user for the price of said item}
Writeln('Please enter the price of product ');
write(Item_Number);
write(' please.');
readln(ItemsPrices[Item_Number]);
{This area below imcrements the counter by 1}
Item_Number:= Item_Number + 1;
{This area below asks the user if they want ot continue or not}
writeln('Do you want to stop entering items? [Yes/No]');
readln(To_End_Or_Not_To_End);
{This area below will determine the programs path}
if To_End_Or_Not_To_End = 'Yes' then
continue
else
break
end;
NameNumber:= Item_Number + 1;
PriceNumber:= Item_Number + 1;
Item_Number:= 1;
{This area below defines the code that will create the Subtotal}
while Item_Number < PriceNumber do
begin
Subtotal:= Subtotal + ItemsPrices[Item_Number];
Item_Number:= Item_Number + 1;
end;
gst_sum:= Subtotal * GST;
Final_Total:= Subtotal + gst;
Item_Number:= 1;
{This area below prints the List of items and prices in reciept form}
while Item_Number < NameNumber do
begin
write(ItemsNames[Item_Number]);
write(' Bz$ ');
write(ItemsPrices[Item_Number]);
write(CRLF);
Item_Number:= Item_Number + 1;
continue
end;
{This area below prints a reciept for the customer}
write('Subtotal'#9#9);
write(Subtotal);
writeln('GST tax 12.5%'#9#9 + 'Bz$');
write(gst_sum);
writeln('Total'#9#9 + 'Bz$');
write(Final_Total);
write(CRLF);
writeln('Tips:______________________________');
writeln(CRLF);
writeln('Total:_____________________________');
writeln(CRLF);
writeln('Print Name:________________________');
writeln(CRLF);
writeln('Signature__________________________');
end.
但是它编译了,它给我一个错误,说“对exitcode 201很兴奋”。我不想改变结构,我不知道编译器发生了什么,因为它拒绝运行而没有立即退出。我正在尝试的是看看它正在退出时会发生什么,因为我设法看到应该在启动时出现的文本。如果有人知道什么是错的,请告诉我。
答案 0 :(得分:1)
你的问题的原因是盯着你,但我怀疑你还不知道它是什么。
当这些行执行时
Writeln('Please enter the name of product ');
write(Item_Number);
write(' please.');
你看到的是
请输入产品名称
0请。
这告诉您Item_Number
的值为0(零)。你的下一个陈述是
readln(ItemsNames[Item_Number]);
您已将ItemNames
数组声明为包含元素1到20,因此没有ItemNames[0]
,这是readln
尝试阅读的内容。与你的
readln(ItemsPrices[Item_Number]);
要解决此问题,请在Item_Number
循环开始之前将值1指定给while
。
接下来,添加语句
readln();
作为程序的最后一行(end.
之前)。这将在您有机会阅读程序输出之前停止控制台窗口关闭。
以上内容至少应该让您开始调试程序。您需要自己学习如何调试其余部分。谷歌自己一些调试器教程,例如这一个https://www.youtube.com/watch?v=LZ90IBa9_8M
在掌握调试自己的代码之前,您将无法使用Pascal或任何其他编程语言。其他人可能不同意,但是它可能是程序员需要的最重要的技能。