hym*_*ode 1 pascal freepascal lazarus
我的 Pascal 程序在主 begin语句和 4 个程序中有一个菜单。在每个程序中,我都会向用户确认他们是否要返回菜单,否则程序将退出,但是每次程序要退出时,它都会再次返回菜单。
procedure quit;
begin
writeln('<Enter> to quit...');
readln;
end
procedure error;
begin
writeln('Error. Try Again...');
readln;
end;
procedure option1;
begin
clrscr;
writeln('this is option 1');
writeln('would you like to continue? (y/n)');
readln(confirm);
if confirm = 'y' then
begin
writeln('something will happen...');
end;
if confirm = 'n' then
begin
writeln('Return to main menu ? (y/n)');
readln(option);
if option = 'y' then
exit
else
quit;
end;
end;
procedure option2;
begin
clrscr;
writeln('this is option2');
writeln('would you like to continue? (y/n)');
readln(confirm);
if confirm = 'y' then
begin
writeln('something will happen...');
end;
if confirm = 'n' then
begin
writeln('Return to main menu ? (y/n)');
readln(option);
if option = 'y' then
exit
else
quit;
end;
end;
Run Code Online (Sandbox Code Playgroud)
主要开始语句:
begin
repeat
1: clrscr;
writeln('Pascal Menu');
gotoxy(4, 3);
writeln('1. Option 1');
gotoxy(4, 4);
writeln('2. Option 2');
gotoxy(4, 5);
writeln('0. Quit Program');
readln(choice);
if choice > 2 then
begin
error
end;
case choice of
1: option1;
2: option2;
0: quit;
end;
until choice = 0;
exit;
end.
Run Code Online (Sandbox Code Playgroud)
我对 Pascal 比较陌生,任何帮助将不胜感激。
调用halt传递所需的退出代码:
halt(0);
Run Code Online (Sandbox Code Playgroud)
如果省略退出代码,则使用默认值0:
halt;
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1196 次 |
| 最近记录: |