Home > Back-end >  Do C simple number guessing game for the first time
Do C simple number guessing game for the first time

Time:09-16

#include
Int main ()
{
Int mynumber=38;
Int yournumber;

Printf (" Input your number: ");
The scanf (" % d ", & amp; Yournumber);
If (yournumber==mynumber)
Printf (" OK! You are right! \n");
The else
If (yournumber> Mynumber)
Printf (" Sorry! Your number is bigger than my number! \n");
The else
Printf (" Sorry! Your number is smaller than my number! \ n!" );
return 0;
}

CodePudding user response:

Can do a upgrade,

Only the right to end the program, or always guess,

CodePudding user response:

reference 1st floor wowpH response:
can do a upgrade,

Only guess the end of the program, or always guess,
thank you

CodePudding user response:

 # include 
#include
#include
# define Max 10
# define min 1
Int main ()
{
Int num, I;
Int a, [10].
char c;
Printf (" please input an arbitrary positive integer within 10 \ n ");
Srand (time (0));
Num=rand () % (Max - min) + min;
for(i=0; I<6; I++)
{
The scanf (" % d ", & amp; A [I]);
The scanf (" % c ", & amp; C);
If (c=='n')
Break;
If (i>
=5){
Printf (" lost ");
Break;
}
If (a==[I] num)
{
Printf (" win ");
Break;
}
Else if (a [I] & gt; Num)
Printf (" too big \ n ");
The else
Printf (" too small \ n ");
Printf (" input new operand \ n ");
Printf (" whether to continue? No (n) input \ n ");
}
return 0;
}


Good coincidence, I also do a ~

CodePudding user response:

Writing is better than mine, in the freshman year, just learning

CodePudding user response:

Add a while loop, the condition is to guess the Numbers, and the answer is not the same, you can cycle until so far

CodePudding user response:

 
Srand ((unsigned) time (NULL));
Num=rand () % 100;

Can do a random number
  • Related