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