#include <stdio.h>
#include <stdlib.h>
#include <time.h>
int main() {
/* rand설명
//rand() % 범위;
srand(time(NULL)); //랜덤 초기화
printf("%d\n", rand() % 3 + 1); */
srand(time(NULL));
int num = rand() % 3 + 1; // 1~100
int answer = 0;
int chance = 3;
while (chance > 0) {
printf("남은 기회 %d번\n", chance--);
printf("숫자를 맞혀 보세요! (1~100) :");
scanf("%d", &answer);
if (answer > num) printf("DOWN ⬇");
else if (answer < num) printf("UP ⬆");
else if (answer == num) {
printf("정답입니다!");
break;
}
if (chance == 0) {
printf("모든 기회를 사용했어요. 실패입니다😢\n 정답은 %d", num);
break;
}
}
return 0;
}
To embed this project on your website, copy the following code and paste it into your website's HTML: