Thread: Issue w/ Guess My Number Program

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #2
    Deathray Engineer MacGyver's Avatar
    Join Date
    Mar 2007
    Posts
    3,210
    Learn how to divide your code into functions. It will help with this kind of stuff.

    Anyway, I've written this type of program out a few times. The idea behind it is that the CPU player needs to have a high limit and a low limit. The limits start at some predetermined numbers. After that, they move dynamically depending upon the guess. If you guess a number, say 10, and it's too low, then you know that the number in question must be greater than 10. So assign 10 to your low limit. Simply put: low = guess; Same concept with the high limit.

    It appears that you do this to some degree, but your guess doesn't appear to be based upon your limits:

    Code:
    compMin = guessNum;
    compVar = (50 - compMin);
    guessNum = (rand() % 50) + compVar;
    Code:
    compMax = guessNum;
    guessNum = (rand() % compMax) + 1;
    Why are you not using your max and min limits in your rand() call properly?
    Last edited by MacGyver; 08-22-2007 at 03:52 AM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Guessing program Hm. Help
    By snugy in forum C Programming
    Replies: 3
    Last Post: 11-17-2008, 11:09 AM
  2. Random number issue
    By swgh in forum C++ Programming
    Replies: 15
    Last Post: 11-14-2008, 10:12 AM
  3. Issue with program that's calling a function and has a loop
    By tigerfansince84 in forum C++ Programming
    Replies: 9
    Last Post: 11-12-2008, 01:38 PM
  4. BOOKKEEPING PROGRAM, need help!
    By yabud in forum C Programming
    Replies: 3
    Last Post: 11-16-2006, 11:17 PM
  5. problem with my prime number program
    By datainjector in forum C Programming
    Replies: 4
    Last Post: 07-12-2002, 12:30 PM