/* Exercise 5.35 solution */ #include #include #include void main () { int x, guess, response; /* seed randomness */ srand (time (NULL)); do { printf ("\nI have a number between 1 and 1000.\n"); printf ("Can you guess my number?\n"); x = 1 + rand () % 1000; printf ("Please type your guess.\n? "); scanf ("%d", &guess); while (guess != x) { if (guess < x) printf ("Too low. Try again.\n? "); else printf ("Too high. Try again.\n? "); scanf ("%d", &guess); } printf ("\nExcellent! You guessed the number!\n"); printf ("Would you like to play again?\n"); printf ("Please type (1=yes, 2=no)? "); scanf ("%d", &response); } while (response == 1); }