/* Guess a digital game */
# Include "stdio. h"
# Include "stdlib. h" // header file used to generate random numbers
Main ()
{
Int x, count = 5, number;
Char answer;
System ("graftable 936 ");
Clrscr ();
Randomize ();
X = random (100) + 1;/* generate a random number between 1 and */
Printf ("\ t [guess digital game] \ n ");
Printf ("---------------------------------------------------------------------------------- \ n ");
Printf ("You have five chances. Please be sure! \ N ");
While (1)
{
Printf ("Enter the number from 1 :");
Scanf ("% d", & number );
Count --;
If (number = x)
{
Printf ("Congratulations, you guessed the number with % d! \ N ", 5-count );
Printf ("continue the game? (Y/n )");
Scanf ("% s", & answer );
If (answer = 'y ')
{
Count = 5;
X = random (100) + 1;
}
Else
{
Printf ("the game ends. Press any key to exit! ");
Break;
}
}
Else
{
If (count> = 1)
{
If (number> x)
{
Printf ("too large! You still have % d chances! \ N ", count );
}
Else
{
Printf ("Too small! You still have % d chances! \ N ", count );
}
}
Else
{
Printf ("wrong! Correct answer: % d! \ N ", x );
Printf ("continue the game? (Y/n )");
Scanf ("% s", & answer );
If (answer = 'y ')
{
Count = 5;
X = random (100) + 1;
}
Else
{
Printf ("the game ends. Press any key to exit! ");
Break;
}
}
}
}
Getch ();
}
From wyzhangchengjin123