c语言实现猜数字小游戏
程序员文章站
2022-05-24 19:03:10
#include
#include
#include
void fun(in...
#include<stdio.h> #include<stdlib.h> #include<time.h> void fun(int c ) { srand((unsigned)time(NULL)); int ret = rand() % 100 + 1; printf("请输入一个数>"); while (1) { scanf("%d", &c); if (c == ret) { printf("正确\n"); break; } else if (c > ret) { printf("猜大了\n"); } else { printf("猜小了\n"); } } } void menu() { printf("********************\n"); printf("****游戏开始********\n"); printf("********************\n"); printf("*****请选择*********\n"); printf("********************\n"); printf("****1 游戏开始******\n"); printf("********************\n"); printf("****2 游戏结束******\n"); printf("********************\n"); printf("********************\n"); } int main() { int c = 0; int num = 0; int input = 0; while (1) { menu(); printf("请选择\n"); scanf("%d", &input); switch (input) { case 1: printf("游戏开始\n"); fun( num); break; { case 2: printf("游戏结束\n"); break; } } //break; } printf("%d", c); system("pause"); return 0;