C language: compile a quiz game.

Source: Internet
Author: User

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...

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.