Here is what I have but it does not work properly.....what am I doing wrong?
#include <iostream>
#include <time.h>
using namespace std;
int main(void)
{
srand(static_cast<int> (time(NULL)));
int upperLimit = 10;
int lowerLimit = 1;
int userGuess = 0;
int count = 0;
int randNum = 0;
const int exit = -1;
cout << "***Welcome to the Guessing Game!***\n";
srand (int(time(NULL)));
randNum = (rand() % (upperLimit - lowerLimit + 1)) + lowerLimit;
cout << "Pick a number between 1-10 (-1 to Exit): ";
cin >> userGuess;
do
{
if (userGuess < randNum)
cout << endl << "Too low, try again." << endl;
else if (userGuess > randNum)
cout << endl << "Too high, try again." << endl;
else if (userGuess == randNum)
cout << endl << "You've guessed wisely" << endl;
else
cout << "The number was " << randNum << " you gave up after " << count << " guesses.\n";
count++;
cin >> userGuess;
}
while(userGuess != randNum && userGuess > 0);
cout << "The number was " << randNum << " it took you " << count << " guesses.\n";
return 0;
}

New Topic/Question
Reply




MultiQuote












|