#include <iostream>
#include <string>
#include <cstdlib>
#include <ctime>
using namespace std;
int main()
{
srand(static_cast<unsigned int>(time(0)));
int randomNumber = rand() % 20 + 1;
int tries = 0;
int guess;
do
{
cout << "Take a shot at guessing a number between 1 and 20: \n";
cin >> guess;
++tries;
if (guess > randomNumber)
{
cout << "too high!\n";
}
else if (guess < randomNumber)
{
cout << " too low!\n";
}
else
{
cout << "You won! " << tries << " tries!\n";
}
if (tries>=5)
{
cout << "You have failed.\n";
break;
}
} while (guess != randomNumber);
system("pause");
return 0;
}