MATLAB爱好者论坛-LabFans.com

MATLAB爱好者论坛-LabFans.com (https://www.labfans.com/bbs/index.php)
-   MATLAB论坛 (https://www.labfans.com/bbs/forumdisplay.php?f=6)
-   -   【文章】**编个猜数字的小游戏** (https://www.labfans.com/bbs/showthread.php?t=681)

spy1120 2007-08-09 22:19

【文章】**编个猜数字的小游戏**
 
[COLOR="Blue"][SIZE="4"]设计猜数字游戏:
首先让电脑产生一个〔1,100〕的随机数A,然后由用户猜测该数字A。如猜测的数字B大于A,则显示“High”,小于则显示“Low”,等于则显示“You Won”,同时退出游戏。用户最多可以猜7次。[/SIZE][/COLOR]
[SIZE="5"][COLOR="Red"]程序:[/COLOR][/SIZE]

%Play the game of guess the number
x=fix(100*rand); %a random number calculated by the computer
n=7;
test=1;
for k=1:7
numb=int2str(n);
disp(['You have a right to ',numb,' guesses'])
disp(['A guess is a number between 0 and 100'])
guess=input('Enter your guess:');
if guess<x
disp('Low')
elseif guess>x
disp('High')
else
disp('You won')
test=0;
break;
end
n=n-1;
end
if test==1
disp('You lost')
end

zhuliting 2007-08-11 00:50

是不是真的哦?

stonewinter 2007-08-14 12:21

支持一下下!!!

diddady 2007-08-21 22:08

这是一题书上的例题啊

ruyan 2007-08-22 15:09

支持下下
:)

Flysnow1127 2007-08-23 15:16

不错不错!!:)

spy1120 2007-08-24 19:46

[QUOTE=diddady;3063]这是一题书上的例题啊[/QUOTE]

嗯,是的
是一本《MATLAB程序设计教程上的例题》
觉得好玩就给大家看看,适合初学者。。。

fengli2008 2007-08-28 13:00

不好玩,没意思~~~~~~

l20020923 2007-09-03 09:01

真的很实用也

穷叟 2007-11-29 17:00

有点参考的,谢谢!


所有时间均为北京时间。现在的时间是 13:00

Powered by vBulletin
版权所有 ©2000 - 2025,Jelsoft Enterprises Ltd.