필터 지우기
필터 지우기

Dice game random number change

조회 수: 1 (최근 30일)
Raz134
Raz134 2020년 12월 5일
편집: Rik 2020년 12월 8일
Hello, i created a game where u can guess the number of a random dice throw. I just have the problem that i cannot be able to change the random number. I tried to change the random number in the last elseif but it doesnt seem to change the value of the first random value created.
Optimal would be if the random dice throw number would change after every guess.
Where is my problem?
My code
clc
play = input('Do guess the number of a thrown dice? und 6 raten? press 1 for yes and 0 for no:');
if play ~= 1
helpdlg('Ok bye')
return;
end
highestNumb = 6;
compNumb = randi([1 highestNumb],1,1);
rightguess = 0;
wrongguess = 0;
usersGuess = input('What number do you pick? ');
trys = 6;
while play == 1 && usersGuess ~= 0 && trys > 0
if usersGuess < compNumb
usersGuess = input('You guessed too low. Enter your next guess, or 0 to quit : ');
wrongguess = wrongguess + 1;
trys = trys -1;
elseif usersGuess > compNumb
usersGuess = input('You guessed too high. Enter your next guess, or 0 to quit : ');
wrongguess = wrongguess + 1;
trys = trys -1;
elseif usersGuess == compNumb
compnumb = randi([1 highestNumb],1,1);
usersGuess = input('You guess right! What is your next pick? : ');
rightguess = randi([1 highestNumb],1,1);
trys = trys - 1;
end
end
if wrongguess == 6
disp('Wow Sie haben nie richtig geraten, mein Beileid')
elseif rightguess >= 2
disp ('Gratulation sie haben mehr als 2 mal richtig geraten')
end

채택된 답변

Walter Roberson
Walter Roberson 2020년 12월 5일
elseif usersGuess == compNumb
compnumb = randi([1 highestNumb],1,1);
You are comparing to compNumb with a capital N, but you assign the new number to compnumb with a lower-case n.
  댓글 수: 1
Raz134
Raz134 2020년 12월 5일
thank you, i missed that

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Strategy & Logic에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by