フィルターのクリア

How to get the right answer

5 ビュー (過去 30 日間)
ka kei yeung
ka kei yeung 2020 年 4 月 23 日
コメント済み: ka kei yeung 2020 年 4 月 24 日
Hello, Guys
i'm trying to cearte a guessword game by using the following code, but the problem is when i'm typing the correct answer, the program still told me that i'm typing the wrong answer. How can i do to change this? Cheers
GuessedWord = randi([0,4]);
if GuessedWord < 0 || GuessedWord > 4
disp("oh you are lcuky and here's what you got !!!!")
else
switch GuessedWord
case 0
A = ('oh my god');
fprintf("** ** ***\n ", A);
case 1
B = ('this');
fprintf("****\n ", B);
case 2
C = ('project');
fprintf("*******\n ", C);
case 3
D = ('is');
fprintf("**\n ", D);
case 4
E = ('hard');
fprintf("****\n ", E);
end
end
A = ('Oh My God');
B = ('This');
C = ('Project');
D = ('is');
E = ('hard');
guess = [A,B,C,D,E];
while (guess ~= GuessedWord)
guess = input("Guess the word:",'s');
if guess ~= GuessedWord
fprintf('Sorry mate, Your guess (%s) is wrong!!!!! \n.' ,guess)
end
if guess == GuessedWord
fprintf('Congratulations!!! You guess is right (%s). \n', guess)
end
end

回答 (1 件)

Image Analyst
Image Analyst 2020 年 4 月 23 日
Use strcmpi()
if strcmpi(guess, GuessedWord)
  1 件のコメント
ka kei yeung
ka kei yeung 2020 年 4 月 24 日
where shoud i put in this if condtion, i still haven't got the idea, i'm so sorry bout that. But thx for the help!!!!

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeSimulink Functions についてさらに検索

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by