帕斯卡退出代码 201
Pascal exitcode 201
我在使用这个程序时遇到问题。项目是做收银机的。
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.
但是它编译了,它向我抛出一个错误,说 "excited with exitcode 201." 我不想改变结构,我不知道编译器发生了什么,因为它拒绝 运行 没有立即退出。我正在尝试的是查看它退出时会发生什么,因为我设法瞥见了启动时应该出现的文本。如果有人知道哪里出了问题,请告诉我。
你的问题的原因就在眼前,但我怀疑你还不够了解它是什么。
当这些行执行时
Writeln('Please enter the name of product ');
write(Item_Number);
write(' please.');
所见即所得
Please enter the name of product
0 please.
这告诉您 Item_Number
的值为 0(零)。你的下一条语句是
readln(ItemsNames[Item_Number]);
您已将 ItemNames
数组声明为具有元素 1 到 20,因此没有 ItemNames[0]
,这正是您的 readln
试图读取的内容。你的
也一样
readln(ItemsPrices[Item_Number]);
要解决此问题,请在 while
循环开始之前将值 1 分配给 Item_Number
。
接下来,添加语句
readln();
作为程序的最后一行(在 end.
之前)。这将阻止控制台 window 在您有机会阅读程序输出之前关闭。
以上至少应该让你开始调试你的程序。您需要学习如何自己调试其余部分。 Google 你自己一些调试器教程,例如这个https://www.youtube.com/watch?v=LZ90IBa9_8M
在您掌握调试自己的代码之前,您将无法掌握 Pascal 或任何其他编程语言。其他人可能不同意,但我认为这可能是程序员需要的最重要的一项技能。
我在使用这个程序时遇到问题。项目是做收银机的。
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.
但是它编译了,它向我抛出一个错误,说 "excited with exitcode 201." 我不想改变结构,我不知道编译器发生了什么,因为它拒绝 运行 没有立即退出。我正在尝试的是查看它退出时会发生什么,因为我设法瞥见了启动时应该出现的文本。如果有人知道哪里出了问题,请告诉我。
你的问题的原因就在眼前,但我怀疑你还不够了解它是什么。
当这些行执行时
Writeln('Please enter the name of product ');
write(Item_Number);
write(' please.');
所见即所得
Please enter the name of product
0 please.
这告诉您 Item_Number
的值为 0(零)。你的下一条语句是
readln(ItemsNames[Item_Number]);
您已将 ItemNames
数组声明为具有元素 1 到 20,因此没有 ItemNames[0]
,这正是您的 readln
试图读取的内容。你的
readln(ItemsPrices[Item_Number]);
要解决此问题,请在 while
循环开始之前将值 1 分配给 Item_Number
。
接下来,添加语句
readln();
作为程序的最后一行(在 end.
之前)。这将阻止控制台 window 在您有机会阅读程序输出之前关闭。
以上至少应该让你开始调试你的程序。您需要学习如何自己调试其余部分。 Google 你自己一些调试器教程,例如这个https://www.youtube.com/watch?v=LZ90IBa9_8M
在您掌握调试自己的代码之前,您将无法掌握 Pascal 或任何其他编程语言。其他人可能不同意,但我认为这可能是程序员需要的最重要的一项技能。