Home > Back-end >  C language guess the word game
C language guess the word game

Time:10-02

 # include & lt; Time. H> 
# include & lt; Stdlib. H>
# include & lt; stdio.h>
The main ()
{
Int magic, guess, counter=0, ret;
Char reply;
Srand (time (NULL));//generate a random number
Do {
Counter=0;
Magic=rand () % 100 + 1;//1-100 random Numbers, used with top
Do {
Printf (" do guess a magic number: ");
Ret=the scanf (" % d ", & amp; Guess);
While (ret!=1)//whether the number of input legitimate
{
While (getchar ()!='\ n');//return on behalf of the end and began to judge
Printf (" do guess a magic number: ");
Ret=the scanf (" % d ", & amp; Guess);
}
If (guess==1) return 0;//input value of 1, quit the game
Counter++;
If (guess & gt; Magic)
Printf (" Wrong! Too big! \n");
Else if (guess & lt; Magic)
Printf (" Wrong! Too small! \n");
The else
Printf (" Right! \n");
} while (guess!=magic & amp; & Counter<10);
Printf (" \ n counter=% d ", counter);
Printf (" Do you want to continue (Y/N/Y/N)?" );
The scanf (" % c ", & amp; The reply);
} while (reply=='Y' | | reply=='Y');
}

CodePudding user response:

What's the problem?
If there should be a start
The main () - & gt; Int main ()
Finally, add the return 0;
I use devc++ copy your code, and the two sentences, can run normally
While (ret!=1)//whether the number of input legitimate and it didn't work

CodePudding user response:

reference 1st floor CHXCHXKKK response:
what's the problem?
If there should be a start
The main () - & gt; Int main ()
Finally, add the return 0;
I use devc++ copy your code, and the two sentences, can run normally
While (ret!=1)//judge whether the number of the input is legal and it didn't work
thank you
I don't have a problem
  • Related