【发布时间】:2010-03-01 05:30:25
【问题描述】:
我之前发布了这个,但它被关闭了,因为我没有展示我的编码尝试,所以这里是一个问题:
SECTIONS
$160 = section 1
$220 = section 2
$280 = section 3
$350 = section 4
$425 = section 5
开发伪代码,接受作为输入的未指定数量的伪装者的名字,这些伪装者每个人都支付了他们的服装的全部费用和每个人已经支付的金额。
化装舞者可能已经支付了乐队五个部分中任何一个部分的服装费用。算法应该根据他/她为服装支付的金额来确定伪装者在哪个部分玩耍。该算法还应确定每个部分中支付服装费用的伪装者数量。
应打印人员姓名和他们支付的部分。还应打印各个部分的列表和注册参加每个部分的总人数,以及每个部分支付的总金额。
这是我的尝试: *注意这是用 Pascal 编程的,我需要帮助来修复它并完成它。请帮助并再次感谢。
program Masqueraders;
uses
WinCrt; { Allows Writeln, Readln, cursor movement, etc. }
const
MAX = 5; {this determine the amount of masquarader entered}
Type
listname = Array[1..MAX] of string;
listsect = Array[1..MAX] of string;
var
names : listname;
sections : listsect;
i, amount, TotalMas, TotalAmt, c1, c2, c3, c4, c5, amt1, amt2, amt3, amt4, amt5 : integer;
begin
amount := 1;
while amount <> 0 do
begin
i := i + 1;
readln(names[i]);
readln(amount);
if(amount = 160) then
begin
c1 := c1 + 1; {Count the number of persons for section 1}
amt1 := amt1 + amount; {accumulate the amount for section 1}
sections[i] := 'Section 1';
end;
if(amount = 220) then
begin
c2 := c2 + 1; {Count the number of persons for section 1}
amt2 := amt2 + amount; {accumulate the amount for section 1}
sections[i] := 'Section 2';
end; {end the IF for section 2}
if(amount = 280) then
begin
c3 := c3 + 1; {Count the number of persons for section 1}
amt3 := amt3 + amount; {accumulate the amount for section 1}
sections[i] := 'Section 3';
end; {end the IF for section 3}
if(amount = 350) then
begin
c4 := c4 + 1;
amt4 := amt4 + amount;
sections[i] := 'Section4';
end; {end If for section 4}
if (amount = 425) then
begin
c5 := c5 + 1;
amt5 := amt5 + amount;
sections[i] := 'Section5';
end;{end the while loop}
TotalMas := c1 + c2 + c3;
TotalAmt := amt1 + amt2 + amt3;
writeln('Name Section'); {Heading for the output}
for i := 1 to MAX do
begin
write(names[i]);
writeln(' ',sections[i]);
end;
writeln('Section 1: ');
write('Masquader: ', c1);
write('Amount: ', amt1);
writeln('Total Number of Masquarader: ', TotalMas);
writeln('Total Amount Paid by masquarader: ', TotalAmt);
结束; 结束。
简而言之,它应该接受一个未定义的人数,并根据他们输入的金额将他们分配到各自的部分,然后计算每个部分的人数。这是我当前的输出:
姓名 John Money=160 Section 1
姓名 Keith Money=220 Section John
这就是我想要的:
姓名 John Money=160 Section1
姓名 Keith Money=220 Section2
【问题讨论】:
-
有效吗?如果没有,您会收到什么错误消息或不正确的输出?如果是这样,你认为它有什么问题?
-
如果您的代码是 Pascal,那么它是 code,而不是伪代码。我认为您可以编辑问题标题以反映这一点。
-
是的,你在写 idk 如何更改标题对不起
-
第一个错误:代码中的拼写错误。