Thread: guessing a number

  1. #1
    Registered User
    Join Date
    Mar 2003
    Posts
    1

    guessing a number

    There is a program in which i am facing difficulties.
    The question is that the user thinks of a number and the
    computer guesses it. We have to guess the numbers from
    1 to 100. If we guess 93 in our mind then we'll have to do
    this step :

    (50+100)/2=75

    if the number we guessed is greater than 75 then.

    ( 100 + 75)/2= 87

    if the number is greater than 87 then,

    (100+87)/2=98

    if the number is less than 98 then,

    (98+87)/2=92

    if the number is greater than 92 then,

    (98+92)/2=95

    if the number we guessed is less than 95 then,

    (95+92)/2=93

    93 was the number we guessed.


    We have to take only '>' , '<' or '=' as inputs.
    hope u understand.

  2. #2
    Registered User
    Join Date
    Nov 2002
    Posts
    1,109
    try searching for binary search. but you will need:

    high variable
    low variable
    mid variable

    do this in a loop. use if statements to check if the number is equal to, less than, or greater than and adjust the variables accordingly.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 6
    Last Post: 02-19-2009, 07:19 PM
  2. xor linked list
    By adramalech in forum C Programming
    Replies: 23
    Last Post: 10-14-2008, 10:13 AM
  3. Issue w/ Guess My Number Program
    By mkylman in forum C++ Programming
    Replies: 5
    Last Post: 08-23-2007, 01:31 AM
  4. My number guessing game
    By The Gweech in forum C++ Programming
    Replies: 7
    Last Post: 06-22-2002, 09:03 AM
  5. Random Number problem in number guessing game...
    By -leech- in forum Windows Programming
    Replies: 8
    Last Post: 01-15-2002, 05:00 PM