I need to create a guessing number program that notifies the user whether or not they're guess is higher or lower to the random number created by the program. My problem is that the program only recognizes that the guess the user makes is lower than the random number. If someone could tell me how I can get the program to recognize if the guess is higher than the random number that would be great. thanks

#include <iostream>
#include <cstdlib>
#include <ctime>

using namespace std;
int main()
{
        int num, guess, diff;
        bool done;

        num = (rand() + time(0)) % 100;
		

		done=false;
      
        
        while (!done)
		{
		cout<<"Enter an integer greater than or equal to 0 and"
            <<" less than 100"<<endl;
         cin>>guess;
		 cout<<endl;
		 diff = num - guess;
			if (diff<0)
			{
               diff==diff*-1;
			}
			if(diff==0)
			{
				cout<<"You guessed the correct number"<<endl;
				done=true;	
			}
		
			if (diff>=50)
                {
                        if(guess>num)
						{
							cout<<"Your guess is very high guess again"<<endl;
						}
						else 
						{
							cout<<"Your guess is very low guess again"<<endl;
						}
                }
                else if (diff>=30 && diff<50)
                {
                        if(guess>num)
						{
							cout<<"Your guess is high guess again"<<endl;
						}
						else
						{
							cout<<"Your guess is low guess again"<<endl;
						}
                }
                else if (diff>=15 && diff<30)
                {
                        if (guess>num)
						{
							cout<<"Your guess is a little high, guess again"<<endl;
						}
						
						else 
						{
							cout<<"Your guess is a little low, guess again"<<endl;
						}
						
				}
                else if (diff>0 && diff<15)
                {
                        if(guess>num)
						{
							cout<<"Your guess is really close, but high. guess again"<<endl;
						}
						else
						{
							cout<<"Your guess is really close, but low, guess again"<<endl;
						}
						
				}
		}
        return 0;
}

line 11: that is a pretty screwy way to generate a random number. The normal method is to first seed the random number generator so that you get a different set of random numbers each time the program is run.

int main()
{
    srand( time(0) );
    int x = rand() % 100:

}

I think you have everything much too complicated. All you have to do is compare the guess with the random number.

if( guess < num)
   cout << "Your guess is too low\n";
else if( guess > num)
   cout << "Your guess is too high\n";
else
   cout << "Congratulations!  you guessed correctly.\n";
This article has been dead for over six months. Start a new discussion instead.