所以我需要在pascal中创建一个食物订购系统,我已经完成了该程序,但是当我订购了两种或更多类型的食物时,该程序只给我一行食物
program orderfood;
var
choice,ramen,sashimi,nigi,tei:integer;
nramen,nsashimi,nnigi,ntei:integer;
Money:Text;
count:integer;
NigiMoney,RamenMoney,TeiMoney,SashimiMoney,FinalMoney:integer;
TeiName,RamenName,SashimiName,NigiName,i:string;
a:array [1..4] of string;
b:integer;
procedure Menu;
begin
writeln('/===============\');
writeln('|Welcome to the |');
writeln('| Japan House! |');
writeln('| 1. Ramen |');
writeln('| 2. Sashimi |');
writeln('| 3. Nigirizushi|');
writeln('| 4. Teishoku |');
writeln('| 5. Receipt |');
writeln('| 9. Leave |');
writeln('\===============/');
writeln('Please Enter your choice!');
readln(choice);
end;
procedure OrderRamen;
begin
writeln('Choice For Ramen:');
writeln('1.Shoyu Ramen $38');
writeln('2.Tonkotsu Ramen $37');
writeln('3.Shio Ramen $35');
writeln('4.Miso Ramen $39');
writeln('5.Tsukemen $45');
writeln('6.Instant Ramen Noddles $30');
writeln('Previous =0');
writeln('Enter your choice: ');
readln(ramen);
case ramen of
1:RamenName:='Shoyu Ramen';
2:RamenName:='Tonkotsu Ramen';
3:RamenName:='Shio Ramen';
4:RamenName:='Miso Ramen';
5:RamenName:='Tsukemen';
6:RamenName:='Instant Ramen Noddles';
end;
if ramen=0
then Menu
else write('How many ramen do you want ? ');
readln(nramen);
if nramen>1 then
case ramen of
1:RamenMoney:=nramen*13;
2:RamenMoney:=nramen*20;
3:RamenMoney:=nramen*18;
4:RamenMoney:=nramen*15;
5:RamenMoney:=nramen*22;
6:RamenMoney:=nramen*22;
end;
if nramen=1 then
case ramen of
1:RamenMoney:=13;
2:RamenMoney:=20;
3:RamenMoney:=18;
4:RamenMoney:=15;
5:RamenMoney:=22;
6:RamenMoney:=22;
end;
end;
procedure OrderSashimi;
begin
writeln('Choice For Sashimi:');
writeln('1.Sake $41');
writeln('2.Akami $40');
writeln('3.Chutoro $50');
writeln('4.Otoro $70');
writeln('5.Hotate $45');
writeln('6.Ikura $40');
writeln('Previous =0');
writeln('Enter your choice: ');
readln(sashimi);
case sashimi of
1:SashimiName:='Sake';
2:SashimiName:='Akami';
3:SashimiName:='Chutoro';
4:SashimiName:='Otoro';
5:SashimiName:='Hotate';
6:SashimiName:='Ikura';
end;
if sashimi=0
then Menu
else write('How many sashimi do you want ? ');
readln(nsashimi);
if nsashimi>1 then
case sashimi of
1:SashimiMoney:=nsashimi*13;
2:SashimiMoney:=nsashimi*20;
3:SashimiMoney:=nsashimi*18;
4:SashimiMoney:=nsashimi*15;
5:SashimiMoney:=nsashimi*22;
6:SashimiMoney:=nsashimi*22;
end;
if nsashimi=1 then
case sashimi of
1:SashimiMoney:=13;
2:SashimiMoney:=20;
3:SashimiMoney:=18;
4:SashimiMoney:=15;
5:SashimiMoney:=22;
6:SashimiMoney:=22;
end;
end;
procedure OrderNigirizushi;
begin
nigi:=0;
writeln('Choice For Nigirizushi:');
writeln('1.Tamago $13');
writeln('2.Sake $20');
writeln('3.Maguro $18');
writeln('4.Ebi $15');
writeln('5.Ikuro $22');
writeln('6.Kani $20');
writeln('Previous =0');
writeln('Enter your choice: ');
readln(nigi);
case nigi of
1:NigiName:='Tamago';
2:NigiName:='Sake';
3:NigiName:='Maguro';
4:NigiName:='Ebi';
5:NigiName:='Ikuro';
6:NigiName:='Kani';
end;
if nigi=0
then Menu
else write('How many nigirizushi do you want ? ');
readln(nnigi);
if nnigi>1 then
case nigi of
1:NigiMoney:=nnigi*13;
2:NigiMoney:=nnigi*20;
3:NigiMoney:=nnigi*18;
4:NigiMoney:=nnigi*15;
5:NigiMoney:=nnigi*22;
6:NigiMoney:=nnigi*22;
end;
if nnigi=1 then
case nigi of
1:NigiMoney:=13;
2:NigiMoney:=20;
3:NigiMoney:=18;
4:NigiMoney:=15;
5:NigiMoney:=22;
6:NigiMoney:=22;
end;
end;
procedure OrderTeishoku;
begin
writeln('Choice For Teishoku:');
writeln('1.Kara-Age Teishoku $45');
writeln('2.Tonkatsu Teishoku $40');
writeln('3.Sashimi Teishoku $35');
writeln('4.Mix Fry Teishoku $39');
writeln('Previous =0');
writeln('Enter your choice: ');
readln(tei);
if tei=0
then Menu
else write('How many Teishoku do you want ? ');
readln(ntei);
case tei of
1:TeiName:='Kara-Age Teishoku';
2:TeiName:='Tonkatsu Teishoku';
3:TeiName:='Sashimi Teishoku';
4:TeiName:='Mix Fry Teishoku';
end;
if ntei>1 then
case ntei of
1:TeiMoney:=ntei*13;
2:TeiMoney:=ntei*20;
3:TeiMoney:=ntei*18;
4:TeiMoney:=ntei*15;
5:TeiMoney:=ntei*22;
6:TeiMoney:=ntei*22;
end;
if ntei=1 then
case tei of
1:TeiMoney:=13;
2:TeiMoney:=20;
3:TeiMoney:=18;
4:TeiMoney:=15;
5:TeiMoney:=22;
6:TeiMoney:=22;
end;
end;
procedure StoreMoney1;
begin
Assign(Money,'C:\Users\jason\Desktop\Ho Chung Hin Sba\real
pg\Money.txt');
rewrite(Money);
writeln(Money,RamenName,' ','*',nramen,' ',RamenMoney);
close(Money);
end;
procedure StoreMoney2;
begin
Assign(Money,'C:\Users\jason\Desktop\Ho Chung Hin Sba\real
pg\Money.txt');
rewrite(Money);
writeln(Money,NigiName,' ','*',nnigi,' ',NigiMoney);
close(Money);
end;
procedure StoreMoney3;
begin
Assign(Money,'C:\Users\jason\Desktop\Ho Chung Hin Sba\real
pg\Money.txt');
rewrite(Money);
writeln(Money,TeiName,' ','*',ntei,' ',TeiMoney);
close(Money);
end;
procedure StoreMoney4;
begin
Assign(Money,'C:\Users\jason\Desktop\Ho Chung Hin Sba\real
pg\Money.txt');
rewrite(Money);
writeln(Money,SashimiName,' ','*',nsashimi,' ',SashimiMoney);
close(Money);
end;
Procedure PrintOut;
begin
b:=1;
reset(Money);
while not EOF(Money) do
begin
readln(Money,i);
a[b]:=i;
writeln(a[b]);
b:=b+1;
end;
close(Money);
end;
begin
repeat
begin
Menu
end;
if choice=1 then
begin
OrderRamen;
StoreMoney1;
end
else if choice=2 then
begin
OrderNigirizushi;
StoreMoney2;
end
else if choice=3 then
begin
OrderTeishoku;
StoreMoney3;
end
else if choice=4 then
begin
OrderSashimi;
StoreMoney4;
end;
until choice=5;
if choice=5 then
begin
PrintOut
end;
if choice=9 then
exit;
end.
结果和输入: 输入1 1 1,2 1 1 结果:细节2但没有1 请帮忙!
答案 0 :(得分:1)
您的StoreMoney
程序全部打开文本文件进行写入,丢弃以前写入的内容。您需要找到编译器的过程/函数,该过程/函数将打开文本文件以进行write-with-append。我已经看到了几种方法,例如Append(f)
和Open(f,'a')
,以及面向对象(或伪对象)的样式,例如F.Open('a')
或{{1} }。