实验二task5
include <stdio.h>
include <stdlib.h>
include <time.h>
int main() {
int luckyDay, guess, attempts = 0;
srand(time(0));
luckyDay = rand() % 30 + 1;
printf("欢迎来到4月幸运日猜测游戏!你有3次机会猜出你的幸运日。\n");
while (attempts < 3) {
printf("请输入你猜测的日期(1-30):");
scanf_s("%d", &guess);
if (guess == luckyDay) {
printf("恭喜你,猜中了!\n");
return 0;
}
else if (guess < luckyDay) {
printf("你猜的日期早了。\n");
}
else {
printf("你猜的日期晚了。\n");
}
attempts++;
}
printf("很遗憾,你的3次机会已用完。你在4月的幸运日是:%d\n", luckyDay);
return 0;
}


浙公网安备 33010602011771号