참고 : 이것은 숙제 임무입니다.사용자가 C++로 말하면 루프를 일찍 끝내는 방법
저는 돼지 게임을하는 프로그램을 만들려고합니다! 내가 (코드 참조) 다음과 같은 문제에 도달 할 때까지
1. First to get 100 GAME POINTS is the victor. 2. On your turn, you roll a dice. If you get a 1 at any roll, you end your turn and add 0 to your GAME SCORE. 3. If you roll any value other than a 1, you have the option to HOLD or PLAY. If you PLAY, your roll is added to your TURN SCORE and you roll again. If you HOLD, your TURN SCORE is added to your GAME SCORE and the turn passes to the computer.
이 게임은 아주 쉽게 따라오고있다 :
int player(){
char PlayAgain = 'Y';
int turn_score = 0;
while (PlayAgain != 'N' || PlayAgain != 'n'){
int dice;
srand(time(NULL));
dice = rand() % 6 + 1;
turn_score = turn_score + dice;
if (dice != 1){
cout << "You rolled a " << dice << "! Would you like to roll again? [Y/N]: ";
cin >> PlayAgain;
if (PlayAgain == 'N' || PlayAgain == 'n'){
/*END TURN AND return turn_score;*/
}
}
if (dice == 1){
cout << endl << "Oops! You rolled a 1! Your turn is ended, and you add nothing to your score.\n";
system("PAUSE");
/*END TURN, NO SCORE ADDED*/
}
}
}
가 어떻게 프로그램을 가질 수 돼지는 다음과 같은 규칙을 가진 게임이다 루프를 조기에 끝내십시오 (HOLDS 또는 주사위 == 1 인 경우). 적절한 값을 반환합니다 (HOLD이면 turn_score를 반환하고, 그렇지 않으면 0을 반환). [두 개의 참고 섹션 참조]
조건이 충족되면 'break' 문을 사용하십시오. – Ares
@ Zaphod 그러면 'while'의 상황에 따라 값을 반환 할 수 없습니다. 그렇습니까? 그렇지 않다면, 휴식이 내가 필요한 것을 성취하지 못합니다. –
더 열심히 시도하십시오 :-) – Gabriel