#include <stdio.h>
void main()
{
long luckyNumber = 15;
int yourInput = 0;
int count = 3; /* The maximum number of tries */
for( ; count>0 ; --count) {
printf("\nYou have %d tr%s left.", count, count == 1 ? "y" : "ies");
printf("\nEnter: "); /* Prompt for a guess */
scanf("%d", &yourInput); /* Read in a guess */
/* Check for a correct guess */
if (yourInput == luckyNumber)
{
printf("\nYou guessed it!\n");
return; /* End the program */
}
/* Check for an invalid guess */
if(yourInput<1 || yourInput > 20)
printf("I said between 1 and 20.\n ");
else
printf("Sorry. %d is wrong.\n", yourInput);
}
printf("\nYou have had three tries and failed. The number was %ld\n",
luckyNumber);
}
|