【请教】初学pascal,自编了一个猜数字游戏
pascal吧
全部回复
仅看楼主
level 1
神大侠 楼主
不知道自己编的怎样,请高手们赐教,谢谢啦!^__^我还有一个问题请教:用pascal猜数字编译成.exe应用程序,到最后输出完输赢情况后窗口立即自动关闭了,请问这个问题可以解决吗?var p,q:array[1..4]of byte; a,b,c,i,j,k:integer;f:boolean;begin writeln('Welcome-come in the game"guess numbers"!Enjoy yourself!'); randomize; f:=true; for i:=1 to 4 do p[i]:=random(10); while f=true do begin f:=false; for i:=1 to 4 do for j:=i-1 downto 1 do if p[i]=p[j] then begin f:=true; p[i]:=random(10); break; end; end; writeln('Please input the numbers'); for k:=1 to 8 do begin write(k,'. '); a:=0; b:=0; for i:=1 to 4 do read(q[i]); f:=true; while f=true do begin f:=false; for i:=1 to 3 do for j:=i-1 downto 1 do if q[i]=q[j] then begin writeln('Wrong numbers.Please reinput'); for c:=1 to 4 do read(q[c]); f:=true; break; end; end; for i:=1 to 4 do for j:=1 to 4 do if p[i]=q[j] then if i=j then a:=a+1 else b:=b+1; f:=false; if a<4 then writeln(' A',a,'B',b) else begin writeln(' You Win!'); f:=true; break; end; end; if f=false then begin writeln(' You lose!'); writeln('The numbers is:'); for i:=1 to 4 do write(p[i],' '); end;end.
2006年05月17日 13点05分 1
level 3
可以在程序执行完加个readln语句试一下
2006年05月17日 13点05分 2
对啊,看下结果哈
2013年05月15日 09点05分
level 1
神大侠 楼主
不管用
2006年05月17日 13点05分 3
level 1
神大侠 楼主
我又修改了一下:label 10;var p,q:array[1..4]of longint;ch:char; a,b,c,i,j,k:integer;f:boolean;begin10:writeln; writeln('Welcome-come in the game"guess numbers"!Enjoy yourself!'); randomize; f:=true; for i:=1 to 4 do p[i]:=random(10); while f=true do begin f:=false; for i:=1 to 4 do for j:=i-1 downto 1 do if p[i]=p[j] then begin f:=true; p[i]:=random(10); break; end; end; writeln; writeln('Please input the numbers,like "0 1 2 3"'); for k:=1 to 8 do begin write(k,'. '); a:=0; b:=0; for i:=1 to 4 do read(q[i]); f:=true; while f=true do begin f:=false; for i:=1 to 4 do begin if (q[i]>9)or(q[i]<0) then begin writeln('Wrong numbers.Please reinput'); write(' '); for c:=1 to 4 do read(q[c]); f:=true; break; end; for j:=i-1 downto 1 do if q[i]=q[j] then begin writeln('Wrong numbers.Please reinput'); write(' '); for c:=1 to 4 do read(q[c]); f:=true; break; end; end; end; for i:=1 to 4 do for j:=1 to 4 do if p[i]=q[j] then if i=j then a:=a+1 else b:=b+1; f:=false; if a<4 then writeln(' A',a,'B',b) else begin writeln(' **** **** **** *** ***** *****'); writeln(' **** ****** **** *** ***** ***'); writeln(' **** ******** **** *** ** ***'); writeln(' **** **** **** **** ***** *** ** ***'); writeln(' **** **** **** **** *** *** ** ***'); writeln(' ******* ******* *** *** ** ***'); writeln(' ***** ***** *** *** *****'); writeln(' *** *** ***** ***** *****'); writeln; f:=true; break; end; end; if f=false then begin writeln(' ********* *** * *'); writeln(' * * * * *'); writeln(' * * * *'); writeln(' ********* * * * *'); writeln(' * *********** * *'); writeln(' * * * * *'); writeln(' * * * * *'); writeln(' * * * * ***********'); writeln; writeln('The numbers is:'); writeln; write(' '); for i:=1 to 3 do write(p[i],' '); writeln(p[4]); writeln; end; writeln('type "q" to quit or type "r" to replay'); while (ch<>'q')and(ch<>'r') do readln(ch); if ch='r' then goto 10;end.
2006年05月19日 13点05分 4
level 1
神大侠 楼主
label 10;var p,q:array[1..4]of longint;ch:char; a,b,c,i,j,k:integer;f:boolean;begin10:writeln; writeln('Welcome-come in the game"guess numbers"!Enjoy yourself!'); randomize; f:=true; for i:=1 to 4 do p[i]:=random(10); while f=true do begin f:=false; for i:=1 to 4 do for j:=i-1 downto 1 do if p[i]=p[j] then begin f:=true; p[i]:=random(10); break; end; end; writeln; writeln('Please input the numbers,like "0 1 2 3"'); for k:=1 to 8 do begin write(k,'. '); a:=0; b:=0; for i:=1 to 4 do read(q[i]); f:=true; while f=true do begin f:=false; for i:=1 to 4 do begin if (q[i]>9)or(q[i]<0) then begin writeln('Wrong numbers.Please reinput'); write(' '); for c:=1 to 4 do read(q[c]); f:=true; break; end; for j:=i-1 downto 1 do if q[i]=q[j] then begin writeln('Wrong numbers.Please reinput'); write(' '); for c:=1 to 4 do read(q[c]); f:=true; break; end; end; end; for i:=1 to 4 do for j:=1 to 4 do if p[i]=q[j] then if i=j then a:=a+1 else b:=b+1; f:=false; if a<4 then writeln(' A',a,'B',b) else begin writeln(' **** **** **** *** ***** *****'); writeln(' **** ****** **** *** ***** ***'); writeln(' **** ******** **** *** ** ***'); writeln(' **** **** **** **** ***** *** ** ***'); writeln(' **** **** **** **** *** *** ** ***'); writeln(' ******* ******* *** *** ** ***'); writeln(' ***** ***** *** *** *****'); writeln(' *** *** ***** ***** *****'); writeln; f:=true; break; end; end; if f=false then begin writeln(' ********* *** * *'); writeln(' * * * * *'); writeln(' * * * *'); writeln(' ********* * * * *'); writeln(' * *********** * *'); writeln(' * * * * *'); writeln(' * * * * *'); writeln(' * * * * ***********'); writeln; writeln('The numbers is:'); writeln; write(' '); for i:=1 to 3 do write(p[i],' '); writeln(p[4]); writeln; end; writeln('type "q" to quit or type "r" to replay'); while (ch<>'q')and(ch<>'r') do readln(ch); if ch='r' then goto 10;end.
2006年05月19日 13点05分 5
level 1
神大侠 楼主
怎么空格都没了?!
2006年05月19日 13点05分 6
level 0
修改一下label 10; var p,q:array[1..4]of longint;ch:char; a,b,c,i,j,k:integer;f:boolean; begin repeatwriteln; writeln('Welcome-come in the game"guess numbers"!Enjoy yourself!'); randomize; f:=true; for i:=1 to 4 do p[i]:=random(10); while f=true do begin f:=false; for i:=1 to 4 do for j:=i-1 downto 1 do if p[i]=p[j] then begin f:=true; p[i]:=random(10); break; end; end; writeln; writeln('Please input the numbers,like "0 1 2 3"'); for k:=1 to 8 do begin write(k,'. '); a:=0; b:=0; for i:=1 to 4 do read(q[i]); f:=true; while f=true do begin f:=false; for i:=1 to 4 do begin if (q[i]>9)or(q[i]<0) then begin writeln('Wrong numbers.Please reinput'); write(' '); for c:=1 to 4 do read(q[c]); f:=true; break; end; for j:=i-1 downto 1 do if q[i]=q[j] then begin writeln('Wrong numbers.Please reinput'); write(' '); for c:=1 to 4 do read(q[c]); f:=true; break; end; end; end; for i:=1 to 4 do for j:=1 to 4 do if p[i]=q[j] then if i=j then a:=a+1 else b:=b+1; f:=false; if a<4 then writeln(' A',a,'B',b) else begin writeln(' **** **** **** *** ***** *****'); writeln(' **** ****** **** *** ***** ***'); writeln(' **** ******** **** *** ** ***'); writeln(' **** **** **** **** ***** *** ** ***'); writeln(' **** **** **** **** *** *** ** ***'); writeln(' ******* ******* *** *** ** ***'); writeln(' ***** ***** *** *** *****'); writeln(' *** *** ***** ***** *****'); writeln; f:=true; break; end; end; if f=false then begin writeln(' ********* *** * *'); writeln(' * * * * *'); writeln(' * * * *'); writeln(' ********* * * * *'); writeln(' * *********** * *'); writeln(' * * * * *'); writeln(' * * * * *'); writeln(' * * * * ***********'); writeln; writeln('The numbers is:'); writeln; write(' '); for i:=1 to 3 do write(p[i],' '); writeln(p[4]); writeln; end; writeln('type "q" to quit or type "r" to replay'); while (ch<>'q')and(ch<>'r') do readln(ch); until ch<>'r';end.
2008年07月02日 04点07分 7
level 7
......石沉大海的帖子们终能慢慢浮出来了
2008年07月02日 04点07分 8
level 5
给整个程序加一个repeat until 0=1
2008年07月02日 13点07分 9
level 0
最后加一个 readln; 停一下
2008年07月03日 13点07分 10
level 6
支持一下
2008年07月19日 01点07分 11
level 4
Program ex1;Const infile = 'ex1.in'; outfile = 'ex1.out';Type p,q:array[1..4]of longint;var a,b,c,i,j,k:integer; f:boolean;ch:char; begin Assign(input, infile); Reset(input); Readln; repeat writeln; writeln('Welcome-come in the game"guess numbers"!Enjoy yourself!'); randomize; f:=true; for i:=1 to 4 do p[i]:=random(10); while f=true do begin f:=false; for i:=1 to 4 do for j:=i-1 downto 1 do if p[i]=p[j] then begin f:=true; p[i]:=random(10); break; end; end; writeln; writeln('Please input the numbers,like "0 1 2 3"'); for k:=1 to 8 do begin write(k,'. '); a:=0; b:=0; for i:=1 to 4 do read(q[i]); f:=true; while f=true do begin f:=false; for i:=1 to 4 do begin if (q[i]>9)or(q[i]<0) then begin writeln('Wrong numbers.Please reinput'); write(' '); for c:=1 to 4 do read(q[c]); f:=true; break; end; for j:=i-1 downto 1 do if q[i]=q[j] then begin writeln('Wrong numbers.Please reinput'); write(' '); for c:=1 to 4 do read(q[c]); f:=true; break; end; end; end; for i:=1 to 4 do for j:=1 to 4 do if p[i]=q[j] then if i=j then a:=a+1 else b:=b+1; f:=false; if a<4 then writeln(' A',a,'B',b) else begin writeln(' **** **** **** *** ***** *****'); writeln(' **** ****** **** *** ***** ***'); writeln(' **** ******** **** *** ** ***'); writeln(' **** **** **** **** ***** *** ** ***'); writeln(' **** **** **** **** *** *** ** ***'); writeln(' ******* ******* *** *** ** ***'); writeln(' ***** ***** *** *** *****'); writeln(' *** *** ***** ***** *****'); writeln; f:=true; break; end; end; if f=false then begin writeln(' ********* *** * *'); writeln(' * * * * *'); writeln(' * * * *'); writeln(' ********* * * * *'); writeln(' * *********** * *'); writeln(' * * * * *'); writeln(' * * * * *'); writeln(' * * * * ***********'); writeln; writeln('The numbers is:'); writeln; write(' '); for i:=1 to 3 do write(p[i],' '); writeln(p[4]); writeln; end; writeln('type "q" to quit or type "r" to replay'); while (ch<>'q')and(ch<>'r') do readln(ch); until ch<>'r'; end.
2008年12月20日 02点12分 12
level 5
怎么玩?
2008年12月27日 03点12分 13
level 1
用个goto语句,一次次循环就可以了,肯定不会退出!!
[url=http://wowui.duowan.com/sig/][img]http://wowui.duowan.com/sig/sigs/ZoTrqCg.png[/img][/url]
2009年01月19日 09点01分 14
level 0
goto语句的一种严重破坏程序结构的语句
goto语句只有刚入门的新手才会使用的
2009年01月19日 13点01分 15
level 0
如果你在看代码时看到有goto语句,这个代码你就没有必要再看下去了
2009年01月20日 00点01分 16
level 5
使用回跳的GOTO语句,会使程序结构难于理解....但不过还好~这个程序还不至于..好久都不用goto了...
2009年01月26日 05点01分 17
level 1
怎么玩怎么玩怎么玩怎么玩怎么玩怎么玩怎么玩怎么玩怎么玩
2009年03月08日 13点03分 18
level 1
A0B1A0B2A1B0A2B1之类的什么意思
2009年03月08日 13点03分 19
level 6
9L until false不就好了,还显得正规
2009年03月25日 13点03分 20
1 2 尾页