C language guessing game code

Written in front: This code uses elementary codes such as random number + loop body + timestamp, etc. It is only for Xiaobai to communicate, for reference!

#include <stdio.h> 
#include <time.h> 
#include <stdlib.h> 
#include <time.h> 
int menu() //define menu 
{ 
	int num; 
	int ample = 0; 
	printf("** **********************************\n"); 
	printf("***** arrange time reasonably , Pay attention to your health!****\n"); 
	printf("********************************* ***\n"); 

	num = rand()% 100 + 1; //Generate random numbers (1---100) 
	printf("Test random number phase:%d\n", num); 
	while (1 ) 
	{ 
		printf("Please enter a random number (0---100):"); //WHILE loop body determines whether the input number meets the conditions 
		scanf_s("%d", &le); 
		if (ample>num) 
		{ 
			printf("Guess it big\n"); 
		}
		else 
		{ 
			if (ample <num) 
				printf("Guess it is small\n"); 
			else 
			{ 
				printf("Guess it ----------------------> Congratulations!\n"); 
				break; 
			} 
		} 
	} 
	printf("*********************************** *\n"); 
	printf("*****is about to restart, please reconfirm! ****\n"); 
	printf("*************** *********************\n"); 


		
} 
int main() 
{ 
	
	int a; 
	srand((unsigned int)time(NULL)); //definition A random number starting value, otherwise the random number executed every time will be the same (every time the computer is turned on, it will be automatically calculated) 
	printf("Welcome to the number guessing game:\n");//Introduce a time function, so that each random number changes with time, but the code parameter that defines the initial value is UNSIGNED type, and the time is a long integer, just use a coercive type conversion
	
	do //As for why NULL is written, because the time parameter requires a pointer type, we will use a null pointer to solve the problem 
	{ 
		printf("Please enter whether to enter the game:"); 
		scanf_s("%d", &a); 
		switch (a) 
		{ 
		case 1: 

			menu(); 
			break; 

		case 0: 
			printf("Exit the program.\n"); 
			break; 
		default: 
			printf("input error, unrecognized [please enter 0/1 to confirm]:"); 

		} 
	} while (a!=0); 

		
	
}


Guess you like

Origin blog.51cto.com/15144773/2676953