用C语言实现一款猜数字游戏
程序员文章站
2022-04-30 09:53:29
用c语言实现一款猜数字游戏
#include
#include
#include
#include...
用c语言实现一款猜数字游戏
#include<stdio.h> #include<stdlib.h> #include<time.h> #include<windows.h> int main() { int start = 1; while (start) { printf("请选择:\n"); printf("*******************\n"); printf("**** 1 开始游戏****\n"); printf("**** 0 退出游戏****\n"); printf("*******************\n"); scanf_s("%d", &start); switch (start) { case 1: { int random; int input; printf("*****游戏开始*****\n"); srand((unsigned)time(null)); random = rand() % 100; input = 0; while (1) { printf("你猜多少:\n"); scanf("%d", &input); if (input > random) { printf("你猜大了\n"); } else if (input < random) { printf("你猜小了\n"); } else { printf("你猜对了!\n"); printf("恭喜您!\n"); sleep(1000); printf("\n\n"); break; } } break; } case 0: { return 0; } default: { printf("选择错误\n"); break; } } } return 0; }