/* guess4.c - lets user keep guessing random number until success YOUR NAME(S), 7/25/2012 */ #include #include #include int main(void) { int target, max = 1, guess = 0; /* GET max FROM USER: REPEAT AS NECESSARY UNTIL IT IS GREATER THAN 1 */ srand(time(NULL)); target = 1 + rand() % max; /* START REPETITION: KEEP GOING AS LONG AS guess DIFFERS FROM target */ printf("Guess a number between 1 and %d: ", max); scanf("%i", &guess); if (guess == target) printf("Correct! Bye.\n"); else { if (guess < target) printf("Too low."); else printf("Too high."); printf(" Try again.\n"); } /* REMEMBER TO TERMINATE THE REPEATING BLOCK */ return 0; }