code is too long
1 回表示 (過去 30 日間)
古いコメントを表示
a = 4;
b = input ('2+2=? ')
if b == a
'ok'
else
b = input ('retry ')
if b == a
'ok'
else
b = input ('retry ')
if b == a
'ok'
else 'NOK'
end
end
end
0 件のコメント
採用された回答
Image Analyst
2013 年 3 月 31 日
編集済み: Image Analyst
2013 年 3 月 31 日
I think you want
a = 4;
b = 0;
while b ~= a
b = input ('2+2=? ');
if b == a
break;
end
fprintf('Incorrect. Try again.\n');
end
fprintf('Correct.\n');
1 件のコメント
Image Analyst
2013 年 3 月 31 日
If you want to limit it to three tries, add a counter:
a = 4;
b = 0;
counter = 1;
while b ~= a && counter <= 3
b = input ('2+2=? ');
if b == a
break;
end
fprintf('Incorrect. Try again.\n');
counter = counter + 1;
end
if counter <= 3
fprintf('Correct.\n');
end
その他の回答 (1 件)
Nicolò
2013 年 3 月 31 日
2 件のコメント
Image Analyst
2013 年 3 月 31 日
This is not an answer to your question. It should have been a comment to my answer so I'll put the response there.
参考
カテゴリ
Help Center および File Exchange で Loops and Conditional Statements についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!