Game in c-guess numbers

Source: Internet
Author: User

Game in c-guess numbers
Program writing: use c to create a random number between 0 and, and follow the prompts to guess the correct number. # Include <stdio. h> # include <stdlib. h> # include <time. h> void menu () {printf ("\ n"); printf ("*********** 1. start the game ************** \ n "); printf (" ************* 0. exit the game *************** \ n "); printf (" \ n ");} int main () {int num = 1; printf ("welcome to the guess number GAME \ n"); while (num) {menu (); printf ("select :"); scanf ("% d", & num); // enter 0 or 1, select 0 and 1 switch (num) {case 1: {int n = 0; int ch = 0; srand (unsigned int) time (NULL); // an unsigned integer random number is generated based on time n = rand () % 101; // generate a random number between 0 and 100 while (1) {printf ("Please guess the number between 0 and \ n"); scanf ("% d ", & ch); // input the size of the guessed number. if (ch> n) {printf ("You guessed it \ n");} else if (ch <n) {printf ("You guessed it \ n");} else {printf ("Congratulations, you guessed it \ n"); break ;}} break;} default: printf ("game exit \ n"); break;} return 0;} run the following results: you are welcome to use the guess digital game *********** 1. start the game ************************** 0. exit the game **************** select: 1, Please guess one (0-100) number 45. if you guess it is too big, Please guess one (0-100) number 35. if you guess it is too small, Please guess one (0-100) when you guess about 40, Please guess one (0-100). Congratulations, you guessed it. *********** 1. start the game ************************** 0. exit the game *************** select: 0 game exit 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.