#include <stdio.h>
#include <stdlib.h>
#include <time.h>
int throwDice();
int getUserGuess();
void playGuessingGame();
int throwDice(){
return rand() % 6 + 1;
}
int getUserGuess(){
int guess;
printf("μ£Όμ¬μλ₯Ό λμ Έ λμ¬ μ«μλ₯Ό λ§ν보μΈμ(1~6): ");
scanf("%d", &guess);
return guess;
}
void playGuessingGame() {
int userGuess, diceResult;
while (1) {
userGuess = getUserGuess();
if (userGuess == 0) {
printf("κ²μμ μ’
λ£ν©λλ€.\n");
break;
}
if (userGuess < 1 || userGuess > 6) {
printf("μλͺ»λ κ°μ μ
λ ₯νμ
¨μ΅λλ€. (1~6 μ¬μ΄λ§ μ
λ ₯ κ°λ₯)\n");
continue;
}
diceResult = throwDice();
printf("μ£Όμ¬μ κ²°κ³Ό: %d\n", diceResult);
if (userGuess == diceResult) {
printf("μΆνν©λλ€! μ«μλ₯Ό λ§μ·μ΅λλ€.\n");
} else {
printf("μμ½μ΅λλ€. λ€μ μλνμΈμ.\n");
}
}
}
int main(){
srand(time(NULL));
printf("μ£Όμ¬μ μ«μ λ§νκΈ° κ²μμ μμν©λλ€.\n");
playGuessingGame();
printf("κ²μ μ’
λ£\n");
return 0;
}