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.
so the problem is that i cant compare the input with the outcome (cause its in another function), any ideas on how to make that happen?(without major changes to the code)
Thanks.
#include <iostream>
#include <string>
#include <cstdlib>
#include <ctime>
usingnamespace std;
int randRange (int lowest,int highest)
{
while (1)
{
int rand_result = rand();
if (rand_result >= lowest && rand_result <= highest)
{
return rand_result;
}
}
}
int main()
{
int input;
srand(time(NULL));
cout << randRange(0, 100)<<endl;
cout << "I picked a number from 1 to 100, guess which one: "<<endl;
cin >> input;
while (1)
{
if (input < ???????)
{
cout << "too low"<<endl;
cin >> input;
}
elseif (input > ???????)
{
cout << "too high"<<endl;
cin >> input;
}
elseif (input == ???????)
{
cout << "right"<<endl;
break;
}
}
std::cin.clear(); // reset any error flags
std::cin.ignore(32767, '\n'); // ignore any characters in the input buffer until we find an enter character
std::cin.get(); // get one more char from the user
return 0;
}