number guessing game, no idea where to start

This is a discussion on number guessing game, no idea where to start within the C Programming forums, part of the General Programming Boards category; hey guys so I made the stupid mistake of taking a course this year becuase one of my friends took ...

  1. #1
    Registered User
    Join Date
    Mar 2004
    Posts
    3

    number guessing game, no idea where to start

    hey guys

    so I made the stupid mistake of taking a course this year becuase one of my friends took it last year and found it dreadfully easy. Unfortunatly the course format was changed this year, and we are learning to program in C (last year they learned the difference between a ball-mouse and an optical mouse).

    My assignment is this: you will write a computer program that actually plays the game. it will make smart guesses until it finds the right answer. you will write your program in the C programming language.
    the rules:
    1/ the user will pick a number between 1 & 100 (but not tell the computer what it is)
    2/ the computer will make a guess
    3/the user will tell the computer whether its guess was too hight, to low, or right on
    4/ steps 2 and 3 repeat until the computer guesses right, when it will output "I got it!""

    there is a good way to play this game - a smart player will always cut the range of possible answers in half with every guess

    the codes that will tell the computer how to evaluate it's guess are:
    input of 0 means: right on
    input of 1 means: too low
    input of 2 means: too high


    I know that I'm going to have to establish variables, (ints upper lower and guess?) and then have a loop where the comptuer calculates what the guess should be based on the last input, then guesses, then gets feedback about whether it guessed too high, low or right on.
    then break the loop.

    but i don't have a clue how to start any of it. back in the day when I was in grade 10, I couldn't get a handle on QBasic, I'm not surprised that even 5 years later, this is still beyond me.

    thank you so much for any help you can give

  2. #2
    Obsessed with C chrismiceli's Avatar
    Join Date
    Jan 2003
    Posts
    501
    psuedo

    Code:
    random_number
    until (enternedNumber = random_number)
        if enternedNumber > random_number
            output too high
        if enternedNumber < random_number
            output too low
        enternedNumber = input;
    when done
    output just right.
    Help populate a c/c++ help irc channel
    server: irc://irc.efnet.net
    channel: #c

  3. #3
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,824
    Have you considered the possibility that this isn't the course for you.

    People come here to learn stuff, not get free get out of jail cards for taking what they thought would be an easy course.

    Cos if you think this is tough, you're in for one hell of a surprise in a couple of months.

    OK, big assumption time.
    I'm assuming that you didn't bunk off the introductory "hello world" lessons which would have taught you the basic printf() and scanf() usage necessary to prompt the user and read some input.
    If you could at least manage that, it would be a start...
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  4. #4
    Registered User
    Join Date
    Mar 2004
    Posts
    3
    Actually, the rest of the course has been pretty easy (HTML, learning about encoding, etc.). There's no doubt in my mind that this isnt' the path that I'm meant to take in life, but this IS just one assignment, not an entire course on programming. This is the only program that we're going to have to write (the year is over in about a month).

    I don't know how much good it would do to justify myself to you, becuase you seem to be set in your opinion that I'm not deserving of help (which may be entierly true -- i'm not denying that it's low to ask for help like this).

    and chris -- thanks. Hopefully when I get home from school again tonight, I can sit down with your suggestion (i even tried writing the pseudo code myself, but was still a little lost), and try to work through things. =)

  5. #5
    Been here, done that.
    Join Date
    May 2003
    Posts
    1,161
    Originally posted by karin
    and chris -- thanks. Hopefully when I get home from school again tonight, I can sit down with your suggestion (i even tried writing the pseudo code myself, but was still a little lost), and try to work through things. =)
    The pseudo code is backwards from your description:
    you will write a computer program that actually plays the game. it will make smart guesses until it finds the right answer.
    Chris' code is the computer thinks of a number (hence "random") and you do the guessing.

    You can use it to a degree, but rewrite it to process the correct algorithm.
    Definition: Politics -- Latin, from
    poly meaning many and
    tics meaning blood sucking parasites
    -- Tom Smothers

  6. #6
    Registered User
    Join Date
    Mar 2004
    Posts
    3
    ok. so i've written what I hope is something approaching the program that i should have.

    however, i'm trying to compile it, and keep getting the error "wrong # args in fucntion call", at which point it aborts the compile.

    i looked around online but couldn't really find anything that would help me figure out what's wrong.

    what does it mean? (i mean, wrong number of arguments in fuction call, right? but what does THAT mean?)

  7. #7
    Just Lurking Dave_Sinkula's Avatar
    Join Date
    Oct 2002
    Posts
    5,006
    >i mean, wrong number of arguments in fuction call, right? but what does THAT mean?

    Here is an example.
    Code:
    #include <stdio.h>
    
    int foo(int x, int y)
    {
       printf("x = %d, y = %d\n", x, y);
       return x + y;
    }
    
    int main(void)
    {
       int result = foo(4); /* ERROR - too few arguments */
       printf("result = %d\n", result);
       return 0;
    }
    7. It is easier to write an incorrect program than understand a correct one.
    40. There are two ways to write error-free programs; only the third one works.*

  8. #8
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,824
    It's simply a matter of being able to count

    Code:
    void foo ( int a, int b ) {  // expects 2 args
    }
    
    ...
    
    int main ( ) {
      foo( 1, 2, 3 );  // gets 3 args
      return 0;
    }
    So find the function it is complaining about, and compare how you're using it with how it is declared.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  9. #9
    Obsessed with C chrismiceli's Avatar
    Join Date
    Jan 2003
    Posts
    501
    sorry for incorrect psuedo code (oxymoron), I misread the description, WaltP is write, it is backwards from your description.
    Help populate a c/c++ help irc channel
    server: irc://irc.efnet.net
    channel: #c

  10. #10
    Registered User caroundw5h's Avatar
    Join Date
    Oct 2003
    Posts
    751
    Originally posted by karin
    ok. so i've written what I hope is something approaching the program that i should have.

    however, i'm trying to compile it, and keep getting the error "wrong # args in fucntion call", at which point it aborts the compile.

    i looked around online but couldn't really find anything that would help me figure out what's wrong.

    what does it mean? (i mean, wrong number of arguments in fuction call, right? but what does THAT mean?)

    Curious as to whether you solved your problem. If not it would be helpful if you post your code. The board has a policy against doing homework, but your attempting it so....I for one would like to C what you got.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Number Guessing
    By blacknapalm in forum C Programming
    Replies: 2
    Last Post: 10-01-2008, 02:48 AM
  2. Random guessing game
    By Nalif in forum C Programming
    Replies: 16
    Last Post: 10-26-2006, 04:05 AM
  3. Game Independent Anti-cheat Project Needs Programmers
    By GIA Project Lea in forum Projects and Job Recruitment
    Replies: 3
    Last Post: 09-15-2005, 08:41 PM
  4. Need some help with a basic tic tac toe game
    By darkshadow in forum C Programming
    Replies: 1
    Last Post: 05-12-2002, 05:21 PM
  5. Array of boolean
    By DMaxJ in forum C++ Programming
    Replies: 11
    Last Post: 10-26-2001, 12:45 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21