/*****************************************************************/ // File : guessnum.c // Purpose : Game of guessing the random number. // Author : Nanda Kishor K N // Mail Id : knnkishor@yahoo.com, nandakishorkn@rediffmail.com // Website : www.c4swimmers.esmartguy.com ( WEB MASTER ) // Group : c4swimmers@yahoogroups.com ( GROUP OWNER ) /*****************************************************************/ #include #include /* Name : main() Purpose : This is the main function that allows you to guess the random number with the help of hints in 10 chances only. This does not call any other function. Parameter : None */ int main() { // Variable Declarations & Initialization // Naming conventions are used like all integer variables should begin with 'i' int iRandom,jIdx,iNum; printf("Find out the number in the range 0 - 500, using hints given by the computer."); // Generate a random number iRandom = rand() % 500; printf("\nI will give you ten chance to find out the number.\nNow the number puzzle starts.\n\n"); for (jIdx = 1; jIdx <= 10; jIdx++) { // Guess the number??? printf("\nNumber %d = ",jIdx); scanf("%d",&iNum); if (iNum < iRandom) // Guessed Number < Generated Random Number printf("Number is less than the given number."); if (iNum > iRandom) // Guessed Number > Generated Random Number printf("Number is greater than the given number."); if (iNum == iRandom) // Guessed Number == Generated Random Number { printf("\n\t\t\t\t!!! Wonderful !!!"); printf("\nIt's great!!! You solved the puzzle & I heartly wish good luck to you."); break; } } return 0; } // End of Program