实验二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;

}

posted @ 2025-03-24 10:44  风火klg  阅读(7)  评论(0)    收藏  举报