c/c++语言开发共享C语言猜数字游戏(数字范围1-100)

#define _CRT_SECURE_NO_WARNINGS 1#include<stdio.h>#include<stdlib.h>#include<time.h>void menu(){printf(“******************************n”);printf(“***** 0.exit 1.play *****n”);printf(“******************************n”);

#define _CRT_SECURE_NO_WARNINGS 1 #include<stdio.h> #include<stdlib.h> #include<time.h> void menu() { 	printf("******************************n"); 	printf("*****  0.exit    1.play  *****n"); 	printf("******************************n");  } void play() { 	printf("您已经进入游戏n"); 	int res = rand() % 100 + 1; 	int num = 0; 	while (1) 	{ 		printf("请输入一个数字"); 		scanf("%d", &num); 		if (num == res) 		{ 			printf("恭喜你猜对了n"); 			break; 		}  		else if (num > res) 			printf("您输入的数字偏大n"); 		else 			printf("您输入的数字偏小n");      } } void  game_over() { 	printf("退出游戏"); } int main() { 	int input = 0; 	srand((unsigned int)time(NULL)); 	do 	{ 		menu(); 		printf("请输入数字开始游戏n"); 		scanf("%d",&input); 		switch (input) 		{ 		case 1: 		{ 			play(); 			break; 		} 		case 0: 		{ 			game_over(); 			break; 		} 		default: 		{ 			printf("请您重新选择n"); 			break; 		} 		} 	} while (input); 	return 0; } 

c/c++开发分享C语言猜数字游戏(数字范围1-100)地址:https://blog.csdn.net/qq_45767476/article/details/107875328

本文来自网络收集,不代表计算机技术网立场,如涉及侵权请联系管理员删除。

ctvol管理联系方式QQ:251552304

本文章地址:https://www.ctvol.com/c-cdevelopment/598231.html

(0)
上一篇 2021年5月8日
下一篇 2021年5月8日

精彩推荐