In this homework assignment, you will write a program called
(for guess a number) that plays a guessing game.
The program will pick a whole number number between 1 and 100,
inclusive, and you will guess what the number is. The program will tell
you how you’re doing with each guess. When you guess correctly, the
program will end after telling you how many guesses it took.
To produce a random
int between 1 and 100, do this:
/* These go before main() */ #include <stdlib.h> #include <time.h> /* These go at the beginning of main() */ srand(time(NULL)); // Seed the random number generator int goal = rand() % 100 + 1; // goal will be 1-100, inclusive
In this example, the prompt is “%”.is what the user types in while running the program. Your output should match exactly.
%% I've thought of a number, 1-100. Your guess is: 999 is not 1-100. Your guess is: 0 is not 1-100. Your guess is: 101 is not 1-100. Your guess is: 1 is cool. Your guess is: 100 is icy. Your guess is: 40 is quite hot. Your guess is: 50 is tepid. Your guess is: 30 is quite hot. Your guess is: 35 is white hot. Your guess is: 36 is correct in 10 guesses.
If you encounter “STACK FRAME LINK OVERFLOW”, then try this:
~cs156/bin/checkin HW2 gan.c
or web checkin.
Turn in someone else’s work.