#include <stdio.h> #include <stdlib.h> #include <time.h> void guess() { int input = 0; int ret; srand((unsigned int)time(NULL)); ret = rand() % 100; printf("请输入0-100内的数字\n"); do { scanf("%d",&input); if(input < ret) printf("猜小了!!!"); else if(input > ret) printf("猜大了!!!"); }while(ret != input); printf("猜对了"); } void show() { int choice; printf("************************\n"); printf("***欢迎使用猜数字游戏***\n"); printf("开始游戏:请按1\n"); printf("退出游戏:请按0\n"); printf("************************\n"); scanf("%d",&choice); switch(choice) { case 1:guess();break; default:return; } } int main() { show(); system("pause"); return 0; }
时间: 2024-10-07 18:58:58