Donate. I desperately need donations to survive due to my health

Get paid by answering surveys Click here

Click here to donate

Remote/Work from Home jobs

Guessing game c++ lvalue required as left operand

I'm trying to make a guessing game using the given function "random in range." Im confused as how to call the function in main to pull up my random number, so I can insert it in my loop. The error "lvalue required" keeps occurring. What am I doing wrong?

#include<ctime>
#include<iostream>
using namespace std;



int random_in_range(int min, int max) //range : [min, max]
{
 static bool first = true;
 if ( first )
 {
 srand((int)time(NULL)); //seeding for the first time only!
 first = false;
 }
 return min + rand() % (max - min);
}


int main() {


      int number, Min, Max;

      cout << "Please enter the Minimum value: ";
      cin >> Min;
      cout << "Please enter the Maximum value: ";
      cin >> Max;

      cout << "Please enter a number between " << Min << "and " << Max << endl;


random_in_range(Min, Max) = number;


      int guess;


      for(int i=0;i<3;i++){

            cout << "Enter your estimate: ";

            cin >> guess;

            if (guess < number)
                  cout << "Your estimate is less, than the secret number" << endl;

            else if (guess > number)
                  cout << "Your estimate is more, than the secret number" << endl;

            else
                  cout << "Your guess is right!" << endl;

      }

      return 0;

}

Comments