How to create a question that loops until it receives correct answer?
    1 回表示 (過去 30 日間)
  
       古いコメントを表示
    
How do I create a program that repeatedly asks the question until the user gives the correct answer? Below is a simple code to explain what exactly I'm asking...
    prompt = 'What age is Seán? ';
    age = (input(prompt));
      ageans = 21;
      if age == ageans
          disp('Correct!');
      else
          disp('Wrong');
      end
So if someone were to answer 37, rather than 21, how would I change the code so that it would loop back to the original question to ask the user again?
0 件のコメント
採用された回答
  Adam
      
      
 2017 年 4 月 24 日
        age = 0;
ageans = 21;
while age ~= ageans
     prompta = 'What age is Seán? ';
     age = (input(prompta));
     if age == ageans
        disp('Correct!');
     else
        disp('Wrong');
     end 
end
その他の回答 (0 件)
参考
カテゴリ
				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!

