Heya. I'm having a problem with my guessing game. It won't stop guessing even after getting the right answer, and it also prints both questions no matter what the user input is. The guessing game is one where the computer guesses the user's number...any help?

#include <stdio.h>
#define max 200

main()
{
    int x, guesses, low, high, mid;
    char response;
    size=max;
    x=100;
    low=1;
    high=max;
    mid=(low+high)/2;
    printf ("Pick an integer from 1 to 200 and I will guess it.");
    printf ("Respond with y is I'm right, n if I'm wrong.\n");
    printf ("I will attempt to guess nine times.");
    while (low<=high) 
    {
          printf ("Is your number %d?\n", mid);
          response=getchar();
          if (response=='n')
          {
               printf ("Is the number less than %d?\n", mid);
               response=getchar();
               if (response=='n')
               {
                     low=mid;
                     mid=(low+high)/2;
               }
               else
               {
                     high=mid;
                     mid=(low+high)/2;
               }
          }
          else if (response=='y') 
          printf ("I got it!\n");
          }
          getch();
}

click on the "Snippets" tab, and study the Binary Search snippet.

Your logic is *way* off the mark.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.