CS156: Intro to C, Part I

Spring 2018

HW 2

CS156 HW2: Guessing Game                

DistanceMessage
> 60icy
≤ 60cold
≤ 45cool
≤ 30tepid
≤ 12quite hot
≤ 2white hot

Description                

In this homework assignment, you will write a program called gan.c (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.                 

Random Numbers                

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

Sample Run                

In this example, the prompt is “%”. Text like this is what the user types in while running the program. Your output should match exactly.                 

    % c11 -Wall gan.c
    % ./a.out
    I've thought of a number, 1-100.
    Your guess is: 999
    999 is not 1-100.
    Your guess is: 0
    0 is not 1-100.
    Your guess is: 101
    101 is not 1-100.
    Your guess is: 1
    1 is cool.
    Your guess is: 100
    100 is icy.
    Your guess is: 40
    40 is quite hot.
    Your guess is: 50
    50 is tepid.
    Your guess is: 30
    30 is quite hot.
    Your guess is: 35
    35 is white hot.
    Your guess is: 36
    36 is correct in 10 guesses.

Debugging                

If you encounter “STACK FRAME LINK OVERFLOW”, then try this:

    export STACK_FRAME_LINK_OVERRIDE=ffff-ad921d60486366258809553a3db49a4a

Notes                

How to submit your homework:                

Use                 

    ~cs156/bin/checkin HW2 gan.c

or web checkin.                 

How to receive negative points:                

Turn in someone else’s work.                 

User: Guest                 

Check: HTML CSS
Edit History Source

Modified: 2018-03-03T15:02                 

Apply to CSU | Contact CSU | Disclaimer | Equal Opportunity
Colorado State University, Fort Collins, CO 80523 USA
© 2018 Colorado State University
CS Building