编写猜数游戏:随机生成0-9的数字,用户输入数字0-9,与生成数字一致即猜对。

如题所述

第1个回答  2009-04-15
我这是用vb写的
<script language="vbscript">
dim n,b(),i,a(3),X,Y,j,k,m,t,c(3),p,v
randomize
for i=0 to 3
do
a(i)=int(10*rnd)
for t=0 to i-1
if a(i)=a(t) then exit for
next
loop while t<i
c(i)=cstr(a(i))
next
for p=1 to 10
n=InputBox("请输入四个不同的数字(0-9):")
redim b(len(n)-1)
for i=1 to len(n)
b(i-1)=mid(n,i,1)
next
X=0
Y=0
for j=0 to 3
if c(j)=b(j) then
X=X+1
end if
next
for k=0 to 3
for m=0 to 3
if c(k)=b(m) then
Y=Y+1
end if
next
next
Y=Y-X
v=10-p
if X=4 and Y=0 then
msgbox "恭喜你完全正确!"
exit for
else
if v=0 then
msgbox "对不起!游戏结束,您输了"
exit for
end if
msgbox "你的测试结果是:"&X&"A"&Y&"B"&"您还有"&v&"次机会!"
end if
next
</script>本回答被提问者采纳
第2个回答  2009-04-03
你想用什么语言写 我这里有个VC++的
相似回答