A clumsy guessing game code reference

Source: Internet
Author: User

directly on the code!!!
#include <stdio.h>#include<stdlib.h>#defineTOP 1000#defineBOTTOM 0/*Made on 2016.7.31 21:17 by Mr.blue and Mr.green This procedure uses block segment, makes the program more simple, but the readability is reduced, hope forgive me*/intMainintargcChar*argv[]) {    inttoobig, Toosmall, temp; Charinput; printf ("This is a clumsy guessing game. Please write down a number of 0~1000 in your heart and press any key to start. \ n");    Getch (); //--------------------guessing block---------------------------------------------------------passing:{Toobig=TOP; Toosmall=BOTTOM; Temp= (Top-bottom)/2;  while(1) {printf ("%d too big, too small or just right (b,s or R) \ n", temp); Switch(input =GetChar ())) {                 Case 'b': {toobig= temp;//Place Toobig as temp because temp is too largetemp = temp-(temp-toosmall)/2;//if it is too large, then temp is to Toosmall binary                     Break; }                 Case 's': {toosmall= temp;//Place Toosmall as temp because temp is too smallTemp = temp + (toobig-temp)/2;//If it is too small, temp is to Toobig binary                     Break; }                 Case 'R':                    GotoLoop//if correct, jump to the result block                default:{//if the input is incorrect, re-enterprintf"Please enter the correct option!\n"); Fflush (stdin); //clear buffer to prevent getchar () from misreading, the following procedure is consistent                    Continue; }            }            if(temp = = Toobig | | temp = = toosmall) {//make a program smarterprintf"You dare to play me? Hey, I saw it! \ n"); GotoRestart;        } fflush (stdin); }    }    //---------------------result block-----------------------------------------------loop:{printf ("I knew I'd guess."); }    //-------------------------Reset Block----------------------------------------------restart:{fflush (stdin); printf ("do you want to start again? (y or N) \ n"); Input=GetChar (); if(Input = ='y'){//If you want to re-play, play it againfflush (stdin); Gotopassing; }        Else if(Input = ='N')//you don't want to shut it down .Exit0); Else{//if the user accidentally enters an error, re-askprintf"Please enter the correct option! \ n"); GotoRestart; }    }    /////////////////////////////////////////////////////////////////////    return 0;}
Run

I guess 89.

  

  I guess 873.

  

  I play it

  

A clumsy guessing game code reference

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.