I'm having problems creating a program that prompts a user to guess the colour.
이전 댓글 표시
I'm stuck because my while loop won't end although I wrote a false condition by using count?? The user is supposed to enter 5 characters. And the program is supposed to check whether there are how many correct guesses of colour and position and correct guesses of colour only. How do I do so? Pls help Thanks Im new to matlab
답변 (3개)
Walter Roberson
2015년 12월 5일
You have
while 1
That will not exit by itself; you need to have a "break" statement inside that loop in order to exit it.
You could be testing count in your "while", such as
while count <= 12345678
but if you do that, be sure to initialize count before the loop, not inside the loop.
댓글 수: 6
Natalia Wong
2015년 12월 5일
Natalia Wong
2015년 12월 5일
편집: Walter Roberson
2015년 12월 5일
Walter Roberson
2015년 12월 5일
find (result == hidden_seq)
gives you the list of matching positions.
What do you want to do with the count? Are you sure you want to change the count if the user does not enter exactly 5 characters? When the user gets everything right, shouldn't you exit the loop?
Natalia Wong
2015년 12월 5일
Natalia Wong
2015년 12월 5일
Image Analyst
2015년 12월 5일
0 개 추천
It seems like this was an earlier question I did not see when I was answering your duplicate question. So now we have this going on in two discussion threads (not good). See my answer over in your more recent posting: http://www.mathworks.com/matlabcentral/answers/259020-creating-a-program-that-guesses-the-colours-not-a-colour#answer_202294
카테고리
도움말 센터 및 File Exchange에서 Shifting and Sorting Matrices에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!