Hi guys;

After abandoning C++ for around a year I have decided to try and return and relearn all the stuff I forgot and couldn't understand to begin with. So I started reading a few C++ eBooks and am looking at one on game programming, this isn't like RPG programming, or really anything graphics related, it just uses the mask of games like tic tac toe and guess my number to teach about arrays and whatnot.

Anyway I have run into a problem while wanting to update my Guess My Number program so that there are two modes, the first where you guess the computer's number, and the second where the computer guesses yours. The second mode is the one where I am having an issue.

First off, it works fine with numbers between 1 and 10, but when I try to do numbers above that, like between 1 and 50 it doesn't work as I want it to. I will set the number to 30; It will guess a number like 32, be told it's too high, then guess 9, be told it's too low, then guess 38, disregarding that if the number 32 is too low then it must guess lower; I tried a few things and it gets it to where the number is eventually guessed, but I was wondering if there was a way I could program it so that if it guesses a number that's too high, it won't guess a higher number. My code is below so you can see the method that I was shown in the book. My code is sort of a mess right now, but it was nice before I added the second mode crap.

Below there is just the code that is in question, and beneath that is the entire file

Any help would be greatly appreciated, this is really annoying me

CODE IN QUESTION
Code:
if (mode == 2)
    {
        printf("Enter a number between 1 and 50: ");
        cin >> number;
        compMax = 50;
        compMin = 1;
        srand(time(0));
        guessNum = (rand() % compMax) + 1;
        guessCount = 1;
        while (play != 'n')
        {
            printf("\nGuess #%d: %d\n",guessCount,guessNum);
            if (guessCount >= 25)
            {
                printf("Well your number couldn't be guessed");
                system("PAUSE");
                break;
            }
            if (guessNum < number)
            {
                printf("Too Low!\n");
                compMin = guessNum;
                compVar = (50 - compMin);
                guessNum = (rand() % 50) + compVar;
                if (guessNum <= compMin || guessNum >= 50)
                {
                    guessNum = (rand() % 50) + compVar;
                    if (guessNum <= compMin || guessNum >= 50)
                    {
                        guessNum = (rand() % 50) + compVar;
                    }
                }
                guessCount++;
                continue;
            }
            if (guessNum > number)
            {
                printf("Too High!\n");
                compMax = guessNum;
                guessNum = (rand() % compMax) + 1;
                if (guessNum <= compMin || guessNum >= 50)
                {
                    guessNum = (rand() % compMax) + 1;
                    if (guessNum <= compMin || guessNum >= 50)
                    {
                        guessNum = (rand() % compMax) + 1;
                    }
                }
                guessCount++;
                continue;
            }
            if (guessNum = number)
            {
                printf("Well it appears your number was guessed on guess %d\n",guessCount);
                system("PAUSE");
                break;
            }
        }
    }
ALL CODE

Code:
/*
    GuessMyNumber.cpp
    Sums up everything from the second chapter via the classic number game ^_^
*/
#include <iostream>
#include <cstdlib>
#include <ctime>

using namespace std;

int main()
{
    int number,guessCount,guessNum,difficulty,mode,compVar,compMax,compMin;
    printf("\tWelcome to the Guess My Number Game!\n");
    char play = 'y';
    printf("\n\tModes\n1) You guess the number\n2) The computer guesses your number\n\nEnter your selection: ");
    cin >> mode;
    if (mode == 1)
    {
        system("CLS");
        printf("\tWelcome to the Guess My Number Game!\nWhat difficulty would you like?\n1) Easy (Numbers 1-5)\n2) Normal (Numbers 1-10)\
        \n3) Hard (Numbers 1-100)\nEnter the number of your selection: ");
        cin >> difficulty;
        switch (difficulty)
        {
        case 1:
             srand(time(0));
             number = (rand() % 5) + 1;
             printf("You chose Easy\nGuess a number between 1 and 5.");
             break;
        case 2:
             srand(time(0));
             number = (rand() % 10) + 1;
             printf("You chose Normal\nGuess a number between 1 and 10.");
             break;
        case 3:
             srand(time(0));
             number = (rand() % 100) + 1;
             printf("You chose Hard\nGuess a number between 1 and 100.");
             break;
        default:
                printf("I don't know what you did, but it caused an error");
                play == 'n';
                break;
        }
             
        guessCount = 0;
        while (play != 'n')
        {
              guessCount++;
              printf("\nGuess %d: ",guessCount);
              cin >> guessNum;
              if (guessNum == number)
              {
                   printf("%d is right! You got it on try number %d\n",guessNum,guessCount);
                   printf("Play again? (y/n): ");
                   cin >> play;
                   if (play == 'y')
                   {
                      system("cls"); // Clears Screen
                      main();        // Starts main() over
                   }
                   else
                   {
                      play = 'n'; // Exits the loop, instead of using a break; since that only exits
                   }              // this IF statement, NOT the while loop
              }
              else if (guessNum > number)
              {
                   printf("%d is too high",guessNum);
                   if (guessCount >= 10)
                   {
                        printf("\nKeep playing? (y/n): ");
                        cin >> play;
                   }
                   else
                   {
                       continue;
                   }
              }
              else if (guessNum < number)
              {
                   printf("%d is too low",guessNum);
                   if (guessCount >= 10)
                   {
                        printf("\nKeep playing? (y/n): ");
                        cin >> play;
                   }
                   else
                   {
                       continue;
                   }
              }
              else
              {
                  printf("I don't know what the ........ you did but it made an error");
                  break;
              }
        }
    }
    if (mode == 2)
    {
        printf("Enter a number between 1 and 50: ");
        cin >> number;
        compMax = 50;
        compMin = 1;
        srand(time(0));
        guessNum = (rand() % compMax) + 1;
        guessCount = 1;
        while (play != 'n')
        {
            printf("\nGuess #%d: %d\n",guessCount,guessNum);
            if (guessCount >= 25)
            {
                printf("Well your number couldn't be guessed");
                system("PAUSE");
                break;
            }
            if (guessNum < number)
            {
                printf("Too Low!\n");
                compMin = guessNum;
                compVar = (50 - compMin);
                guessNum = (rand() % 50) + compVar;
                if (guessNum <= compMin || guessNum >= 50)
                {
                    guessNum = (rand() % 50) + compVar;
                    if (guessNum <= compMin || guessNum >= 50)
                    {
                        guessNum = (rand() % 50) + compVar;
                    }
                }
                guessCount++;
                continue;
            }
            if (guessNum > number)
            {
                printf("Too High!\n");
                compMax = guessNum;
                guessNum = (rand() % compMax) + 1;
                if (guessNum <= compMin || guessNum >= 50)
                {
                    guessNum = (rand() % compMax) + 1;
                    if (guessNum <= compMin || guessNum >= 50)
                    {
                        guessNum = (rand() % compMax) + 1;
                    }
                }
                guessCount++;
                continue;
            }
            if (guessNum = number)
            {
                printf("Well it appears your number was guessed on guess %d\n",guessCount);
                system("PAUSE");
                break;
            }
        }
    }
    
    cin.ignore();
    system("cls");
    cout << "Hit \"Enter\" to END";
    cin.ignore();
    return 0;   
}