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