Hey guys im writing a simply HiLo game.
I cant get my do while statement to work correctly. I want it to stop running the program after you get the right answer. Right now everything works properly but it continues even after you get the right answer. Im using microsoft visual 2010. Also let me know if you see anything that is messy or I could have done easier. Mind that I am still new. I am reteaching my self after 1 semester of learning.
Also is there a way i can change the setting and have the program stay open without using the cin.clear(); cin.ignore(255, '\n'); cin.get(); at the end?
#include <ctime> //for time
#include <cstdlib> //for rand()
using namespace std;
unsigned int GetRandomNumber(int nLow, int nHigh)
nNum = (rand() % (nHigh - nLow +1) + nLow);
if (nCheck == nNum)
cout << "Correct!" << endl;
cout << "It took you " << nTry << " trys." << endl;
else if (nCheck < nNum)
cout << "Too low try Again." << endl << endl;
else if (nCheck > nNum)
cout << "Too high try again." << endl << endl;
nNum = GetRandomNumber(1, 100);
for (nTry = 0; nTry < 10; nTry++)
cout << "You have " << 10 - nTry << " trys to guess a number 1-100: ";
cin >> nCheck;
while (Check() == 0);