The first C language implementation of the Guess number game

Source: Internet
Author: User

#include  <stdio.h> #include  <Windows.h> #include  <stdlib.h> #include  < stdio.h> #include  <Windows.h> #include  <stdlib.h> #include  <time.h>void  Output () {printf ("*********************   Welcome to play guessing number game    ***********************\n");p rintf ("*********************  input 1 into the Guess number game  ***********************\n");p rintf ("*********************  Enter 0 Exit guess number game  ***********************\n ");} Int main () {int charge = 1;while (charge) {output ();p rintf ("Please select;:"); scanf ("%d", &charge ); switch (charge) {Case 1:{int value = 0,input = 0;srand (  (unsigned int) Time ( NULL )  ); Value = rand ()%101;while (1) {printf ("Please enter the number you guessed:"); scanf ("%d", &input); if (input<value) {printf ("Your answer is small");} Else if (input>value) {printf ("you answered Big");} else {printf ("Congratulations on your correct answer \ n");  }break; }default:{printf ("Game over \"); System ("Pause"); return 0;} 

1, the appeal is the code realization, the operation result;

650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M00/75/7C/wKiom1Y6BwPyFNycAAAeW3Zc-xw940.gif "title=" gs.gif "alt=" Wkiom1y6bwpyfnycaaaew3zc-xw940.gif "/>

2, thinking analysis;

(1) is to find a way to get a number, and each time the value of the different;

WORKAROUND: The rand () function can produce a random number, but requires a seed

Srand ((unsigned int) time (NULL)) The seed of the//rand () function

(2) with the random value of the first step, the guessing number game is achieved by comparing the numbers you enter.

(3) In order to always be able to play the game, so put in a while loop to exit the game through the flag flag.

3, Summary: To do each program to achieve practical problems, thinking and logic must be clear, first thought and logic to write code again.

The first C language implementation of the Guess number game

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.