C language: compile a quiz game.
Compile a quiz game. Program:
# Include <stdio. h> # include <time. h> void menu () {printf ("*** welcome to challenge guessing digital games *** \ n "); printf ("***** select start or exit ***** \ n"); printf ("******* 1. start 0. exit ****** \ n ");} void game () {int num = 0; srand (unsigned) time (NULL )); // generate different random numbers as time changes int ret = rand () % 100 + 1; // It is the number of seconds from a time point to this time while (1) {printf ("Please guess:"); scanf ("% d", & num); if (num = ret) {printf ("You are really smart, you guessed it! \ N "); break;} else if (num> ret) {printf (" You are stupid, guess it's big! \ N ");} else if (num <ret) {printf (" you're stupid, you can guess it! \ N ") ;}}int main () {int input = 1; while (input) {menu (); printf (" select :"); scanf ("% d", & input); switch (input) {case 0: break; case 1: game (); break; default: break;} return 0 ;}
Result: you are welcome to start or quit the game. start 0. exit ***** please select: 1 Please guess number: 50 you are stupid, guess small! Guess the number: 75. You're stupid! Please guess the number: 100. You are dumb! Guess the number: 85. You're stupid! Guess the number: 93. You are stupid! Guess the number: 90. You are stupid! Guess the number: 87. You're stupid! Guess the number: 88. You're stupid! Guess the number: 89. You are really smart. You guessed it! * ** Welcome to challenge the guess digital game ******* please choose to start or quit ************ 1. start 0. exit ***** select: 0 press any key to continue...