The problem is at the end of the loop. If you run out of tries then you need to use a
break
statement to get out of the loop. And after exiting the loop you should print the fail or success message, depending on whether
iNum
and
iCompNum
are equal or not. So change it to:
else if (tries >= 10)
{
break;
}
} while (iNum != iCompNum);
if (iNum == iCompNum)
{
cout << "You Lose! Correct Answer is:" << iNum << endl;
}
else
{
cout << "You win, I cannot find it" << endl;
}
return 0;
}