#include <iostream>
#include <ctime>
#include <cstdlib>
using namespace std;
int main()
{
srand(time(NULL));
int tries = 0;
int iNum;
int UpperLim = 100;
int LowerLim = 10;
int iCompNum;
cout << "Enter a number: ";
cin >> iNum;
do
{
iCompNum = rand() % (UpperLim - LowerLim) + LowerLim;
cout << "\nComputer's guess(" << 10 - tries << " tries left): ";
cout << iCompNum;
++tries;
if (iNum > iCompNum)
{
cout << "\nThe number is less than the entered..!(" << 10 - tries << " tries left)\n\n";
LowerLim = iCompNum+1;
}
else if (iNum < iCompNum)
{
cout << "\nThe number is greater than the entered..!(" << 10 - tries << " tries left)\n\n";
UpperLim = iCompNum-1;
}
else if (iNum == iCompNum)
{
cout << "\nYou got my number!!!\n\nYou guessed the number in just " << tries << " tries!\n\n";
}
else if (tries >= 10)
{
cout << "You Lose!Correct Answer is:" << iNum << endl;
}
} while (iNum != iCompNum);
return 0;
}
Dilshan_2 0 Newbie Poster
Dilshan_2 0 Newbie Poster
Reverend Jim 4,968 Hi, I'm Jim, one of DaniWeb's moderators. Moderator Featured Poster
Dilshan_2 commented: please refer below comment +0
Dilshan_2 0 Newbie Poster
Dilshan_2 0 Newbie Poster
Dilshan_2 0 Newbie Poster
Reverend Jim 4,968 Hi, I'm Jim, one of DaniWeb's moderators. Moderator Featured Poster
Dilshan_2 commented: Thank You for the help +0
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.