home *** CD-ROM | disk | FTP | other *** search
- #include <stdio.h>
- #include <libc.h>
- extern void srandom();
-
- main() {
- int theNumber, guess, numGuesses;
- char still_playing = 'y';
- char still_guessing;
- while (still_playing == 'y') {
- srandom(time(0));
- theNumber = random() % ((100)+1);
- numGuesses = 1;
- still_guessing = 'y';
- while (still_guessing == 'y') {
- printf("Guess a number from 1 to 100: ");
- scanf("%d", &guess);
- if (guess == theNumber) {
- printf("Correct in %d guesses!\n", numGuesses);
- still_guessing = 'n';
- printf("Do you want to play again (y/n)? ");
- scanf("%1s", &still_playing);
- }
- else if (guess > theNumber)
- printf("Guess %d is too high\n", numGuesses);
- else if (guess < theNumber)
- printf("Guess %d is too low\n", numGuesses);
- numGuesses ++;
- }
- }
- }
-
-