"Write a program that picks a number between 1 and 100, and then lets the user guess what the number is. The program should tell the user if their guess is too high, too low, or just right."
My only problem is that when I try to pass the number that my generator generates to a variable, it messes everything up.
#include <iostream>
#include <cstdlib>
#include <ctime>
usingnamespace std;
int randRange(int low, int high)
{
return rand() % ( high - low + 1) + low;
}
int main()
{
int userGuess;
int actualNumber;
srand( time( NULL ) );
//Let's test the function to see if it works:
for(int i = 0; i < 5; ++i)
{
cout << randRange(1,100) << endl;
}
//Well, that worked. Let's try passing the number generated into int actualNumber:
randRange(1,100) >> actualNumber;
cout << actualNumber << endl;
//Uhhh.
}
Anyone know how I can pass whatever the generator generates into a variable? Thanks
You seem to be confused. You're treating the >> operator like you would with streams from the standard library. However, what you're actually using is the bitwise right-shift operator, not the extraction operator. Surely you know how to assign a value to something?