How to realize simple number guessing Mini Game with C language
This article mainly introduces the C language how to achieve simple number guessing Mini Game, the article is very detailed, has a certain reference value, interested friends must read it!
The number guessing game is to make the game machine randomly generate a positive integer less than 100.
The user enters a number to guess it, which requires you to write a program to automatically compare it with the randomly generated number.
And hint big ("Too big"), or small ("Too small"), equal means guessed
If you guess, end the program. The program is also required to count the number of guesses. If you guess the number once, it prompts "Bingo!"
If the number is guessed within 3 times, it prompts "Lucky You!"
If the number is guessed more than 3 times but within N (> 3) times (including the Nth time), the prompt is "Good Guess!"
If you don't guess more than N times, prompt "Game Over" and end the program.
If the user enters a negative number and also outputs "Game Over" before reaching N times, and ends the program
# include # include int main () {printf ("the rules of the game are as follows: there are two modes in the game that require the user to enter the number 1 or 2 to choose, and then the user enters his own guess and prompts to approach the answer\ n") Printf ("if guessing the number once prompts Bingo!\ nIf it is guessed within 3 times, it prompts Lucky You!\ nIf it is more than 3 times but includes the Nth time within N (> 3) times, it prompts Good Guess!\ nIf it is not guessed more than N times, it prompts Game Over\ nIf the user enters a negative number before N times, it also outputs Game Over\ n") PlaySound ("background", NULL, SND_FILENAME | SND_ASYNC | SND_LOOP); int aMagic NMagazine iMagnum; printf ("Please choose your mode: 1. The computer randomly generates 0-10 maximum guesses; 2. The default maximum number is 5); printf ("Please enter the mode code of your choice:"); scanf ("% d", & n); printf ("the game has started"); if (unsigned 1) {srand ((unsigned) time (NULL)); a=rand () 0; N=rand (); for (iTune1) printf ("guess big\ n"); else if (x > 0&&x0&&x)