我的程序應該允許用戶選擇從菜單冰淇淋然後添加價格爲冰淇淋展示冰cream.However我的總價輸出是錯誤的總價。例如,如果我選擇1和2,答案應該是1.5 + 1.7 = 3.2,但是我得到3.4。另外,如果我選擇2我只會得到錯誤。請幫幫我。價格在菜單+總價(帕斯卡)
program iceCream;
var
count,i: integer;
price:array[1..50]of real;
totalPrice: real;
choice: integer;
begin
count:= 0;
writeln (' ICE CREAM FLAVOUR');
write (' 1.Vanilla: RM 1.50 | 3.Chocolate: RM 2.00');
writeln;
write (' 2. Strawberry: RM 1.70 | 0. Exit ');
writeln;
repeat
write (' Enter your choice(number): ');
readln (choice);
if choice <= 3 then
count:= count+1
else
writeln ('Invalid choice');
case choice of
1: begin
price[i]:= 1.50;
end;
2: begin
price[i]:= 1.70 ;
end;
3: begin
price[i]:= 2.00;
end;
end;
for i:= 1 to count do
begin
totalPrice:= totalPrice+price[i];
end;
until choice = 0;
writeln (' Total ice-cream: ', count);
readln;
writeln (' Total price: RM ', totalPrice:2:2);
readln;
end.