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