matlab编程题~急!

来源:百度知道 编辑:UC知道 时间:2024/06/06 16:27:31
大家帮帮忙 产生[1,100]随机整数.如猜测数大于产生的随机数,则显示“HIGN”,小于显示“LOW”,等于会显示“WIN”同时退出游戏,用户最多猜7次
答对了赠送25分 我只有这些分了 拜托大家了

clear;
clc;
result = floor(rand()*99+1);

isRight = 0;
userData=-1;

for i = 1:7
userData = input('Please input the number: ');
if(userData == result)
isRight = 1;
disp('WIN');
break;
elseif(userData > result)
disp('HIGH');
else
disp('LOW');
end
end

if(isRight == 0)
disp('Sorry, you failed!');
end

rndnum=round(1+rand(1)*99);
count=0;
while (count<7)
x=input('请输入一个猜测数:');
if (x==rndnum)
disp('WIN');
break;
elseif (x>rndnum)
disp('HIGN');
elseif (x<rndnum)
disp('Low');
end
count=count+1;
end

if (count==7)
sprintf('答案:%d',rndnum)
end