Dylan and Liz
2012-07-25 20:34:57 UTC
#include
#include
#include
using namespace std;
int main ()
{
unsigned short int randomNr;
unsigned short int numberGuess=1;
unsigned short int guessedNr=0;
const int maxNrOfGuess = 15;
char answer='y';
;
srand((unsigned)time(0));
randomNr= 1+(rand()%100);
while (answer=='y'){
numberGuess=1;
guessedNr=0;
cout << "Guess a number between 1 and 100 : ";
cin >> guessedNr;
while (numberGuess <= maxNrOfGuess && guessedNr != randomNr){
cout<
(guessedNr < randomNr) ? cout<<"Guess higher! " : cout<<"Guess lower! ";
cout<< maxNrOfGuess - numberGuess << " more guesses \n";
numberGuess++;
if (numberGuess <= maxNrOfGuess){
cout << "Make a guess (1-100) : ";
cin >> guessedNr;
}
}
if (numberGuess > maxNrOfGuess)
cout<< " You ran out of guesses and have lost the game.";
else
cout<< " You win!";
cout<<"\nWould you like to play again (y/n): ";
cin>> answer;
}
char f;
cin >> f;
}
So where am I messing up and how can I make it not give me the answer?