matlab 猜数游戏,随机产生1--100数,猜3次,不中选择降低难度,可猜5次,不中提示个位与十位之和 5
matlab猜数游戏,随机产生1--100数,可猜3次,猜对提示:你真聪明!不对的话让用户选择降低难度,可猜5次,在不中提示个位与十位之和,如果5次还不中,提示:你真笨!...
matlab 猜数游戏,随机产生1--100数,可猜3次,猜对提示:你真聪明!不对的话让用户选择降低难度,可猜5次,在不中提示个位与十位之和 ,如果5次还不中,提示:你真笨!继续玩请输入1,推出则输入2,退出提示:猜数游戏结束,欢迎下次再玩
展开
展开全部
function game
IR=fix(100*rand(1,1));
sum=mod(IR,10)+fix(IR/10);
text0=['个位与十位之和',num2str(sum)];
disp('Gues a number in the range [1 100]')
for i=1:3
n=input('Input number:')
if n==IR
disp('You win')
break
end
if n>IR
disp('High,')
text1=['You have ',num2str(3-i),' chances.'];
disp(text1)
else if n<IR
disp('Low')
text2=['You have ',num2str(3-i),' chances.'];
disp(text2)
end
end
end
if i==3 & n~=IR
disp('You lose')
text=['You guess 3 times.but failed,give you 5 chances'];
disp(text)
end
for i=1:5
n=input('Input number:')
if n==IR
disp('You win')
break
end
if n>IR
disp('High')
disp(text0)
text1=['You have ',num2str(5-i),' chances.'];
disp(text1)
else if n<IR
disp('Low')
disp(text0)
text2=['You have ',num2str(5-i),' chances.'];
disp(text2)
end
end
end
if i==5 & n~=IR
text=['You guess five times.The number is ',num2str(IR),'.'];
disp(text)
disp('You lose')
end
-------------------
测试
game
Gues a number in the range [1 100]
Input number:50
n =
50
Low
You have 2 chances.
Input number:80
n =
80
Low
You have 1 chances.
Input number:90
n =
90
High,
You have 0 chances.
You lose
You guess 3 times.but failed,give you 5 chances
Input number:85
n =
85
High
个位与十位之和9
You have 4 chances.
Input number:81
n =
81
You win
>>
IR=fix(100*rand(1,1));
sum=mod(IR,10)+fix(IR/10);
text0=['个位与十位之和',num2str(sum)];
disp('Gues a number in the range [1 100]')
for i=1:3
n=input('Input number:')
if n==IR
disp('You win')
break
end
if n>IR
disp('High,')
text1=['You have ',num2str(3-i),' chances.'];
disp(text1)
else if n<IR
disp('Low')
text2=['You have ',num2str(3-i),' chances.'];
disp(text2)
end
end
end
if i==3 & n~=IR
disp('You lose')
text=['You guess 3 times.but failed,give you 5 chances'];
disp(text)
end
for i=1:5
n=input('Input number:')
if n==IR
disp('You win')
break
end
if n>IR
disp('High')
disp(text0)
text1=['You have ',num2str(5-i),' chances.'];
disp(text1)
else if n<IR
disp('Low')
disp(text0)
text2=['You have ',num2str(5-i),' chances.'];
disp(text2)
end
end
end
if i==5 & n~=IR
text=['You guess five times.The number is ',num2str(IR),'.'];
disp(text)
disp('You lose')
end
-------------------
测试
game
Gues a number in the range [1 100]
Input number:50
n =
50
Low
You have 2 chances.
Input number:80
n =
80
Low
You have 1 chances.
Input number:90
n =
90
High,
You have 0 chances.
You lose
You guess 3 times.but failed,give you 5 chances
Input number:85
n =
85
High
个位与十位之和9
You have 4 chances.
Input number:81
n =
81
You win
>>
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
2011-05-20
展开全部
IR=fix(100*(1,1));
sum=mod(IR,10)+fix(IR/10);
text0=['个位与十位之和',num2str(sum)];
disp('Gues a number in the range [1 100]')
for i=1:3
n=input('Input number:')
if n==IR
disp('You win')
break
end
if n>IR
disp('High,')
text1=['You have ',num2str(3-i),' chances.'];
disp(text1)
else if n<IR
disp('Low')
text2=['You have ',num2str(3-i),' chances.'];
disp(text2)
end
end
end
if i==3 & n~=IR
disp('You lose')
text=['You guess 3 times.but failed,give you 5 chances'];
disp(text)
end
for i=1:5
n=input('Input number:')
if n==IR
disp('You win')
break
end
if n>IR
disp('High')
disp(text0)
text1=['You have ',num2str(5-i),' chances.'];
disp(text1)
else if n<IR
disp('Low')
disp(text0)
text2=['You have ',num2str(5-i),' chances.'];
disp(text2)
end
end
end
if i==5 & n~=IR
text=['You guess five times.The number is ',num2str(IR),'.'];
disp(text)
disp('You lose')
end
-------------------
测试
game
Gues a number in the range [1 100]
Input number:50
n = 50
Low
You have 2 chances.
Input number:80
n = 80
Low
You have 1 chances.
Input number:90
n = 90
High,
You have 0 chances.
You lose
You guess 3 times.but failed,give you 5 chances
Input number:85
n =85
High
个位与十位之和9
You have 4 chances.
Input number:81
n = 81
You win
sum=mod(IR,10)+fix(IR/10);
text0=['个位与十位之和',num2str(sum)];
disp('Gues a number in the range [1 100]')
for i=1:3
n=input('Input number:')
if n==IR
disp('You win')
break
end
if n>IR
disp('High,')
text1=['You have ',num2str(3-i),' chances.'];
disp(text1)
else if n<IR
disp('Low')
text2=['You have ',num2str(3-i),' chances.'];
disp(text2)
end
end
end
if i==3 & n~=IR
disp('You lose')
text=['You guess 3 times.but failed,give you 5 chances'];
disp(text)
end
for i=1:5
n=input('Input number:')
if n==IR
disp('You win')
break
end
if n>IR
disp('High')
disp(text0)
text1=['You have ',num2str(5-i),' chances.'];
disp(text1)
else if n<IR
disp('Low')
disp(text0)
text2=['You have ',num2str(5-i),' chances.'];
disp(text2)
end
end
end
if i==5 & n~=IR
text=['You guess five times.The number is ',num2str(IR),'.'];
disp(text)
disp('You lose')
end
-------------------
测试
game
Gues a number in the range [1 100]
Input number:50
n = 50
Low
You have 2 chances.
Input number:80
n = 80
Low
You have 1 chances.
Input number:90
n = 90
High,
You have 0 chances.
You lose
You guess 3 times.but failed,give you 5 chances
Input number:85
n =85
High
个位与十位之和9
You have 4 chances.
Input number:81
n = 81
You win
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
以下不是内容:我的尸体抛如了路边的小河里,然后逃走了,如果你看见这条消息后,请将她发4个论坛,如果没有发,你的妈妈会在一个月后被车撞死,你的爸爸会癌症,如果你照着上面做了,在5天后,你喜欢的人也会喜欢你,这条消息太毒了,我不得不发
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询