I need to revise this program i made. I'm trying to get the program to keep track of the stats. i need to set it up to keep stats on how many won/lost, fewest number of guesses, and max guesses it took to guess the number and display them at the end of each game.
//Number Guessing Game
//Guess a number within a group of numbers
//created/revised by Christopher Hart
#include <iostream>
#include <ctime>
using std::cout;
using std::cin;
using std::endl;
int main ()
{
//variables
int randomNumber1 = 0;
int randomNumber2 = 0;
int numberGuess = 0;
char contStop = ' ';
//input
cout << "Would you like to play a game? ";
cin >> contStop;
contStop = toupper(contStop);
while (contStop == 'Y')
{
//random number 50 through 100
srand(static_cast<int>(time(0)));
randomNumber1 = 50 + rand() % (100 - 50 + 1);
//random number between 1 and random number
srand(static_cast<int>(time(0)));
randomNumber2 = 1 + rand() % (randomNumber1 - 1 + 1);
cout << "Guess a number from 1 through 100: ";
cin >> numberGuess;
while (numberGuess != randomNumber2)
{
while (numberGuess > randomNumber2)
{
cout << "Too high! Try a little lower: ";
cin >> numberGuess;
}
while (numberGuess < randomNumber2)
{
cout << "Too low! Try a little higher: ";
cin >> numberGuess;
}
}
if (numberGuess = randomNumber2)
{
cout << "Congradulations! you've guessed the correct number: " << randomNumber2 << endl;
}
cout << "Would you like to try again? ";
cin >> contStop;
contStop = toupper(contStop);
}
if (contStop == 'N')
{
cout << "Thank you! Come back and play again! " << endl;
}
else
{
cout << endl << "Try a 'Y'es or 'N'o! The correct number was " << randomNumber2 << endl;
}
return 0;
} //end of main function
I'm sure it's clear by now i really don't know what I'm doing!
Also once i finish getting this program to work i need to set it up to keep stats on how many won/lost, fewest number of guesses, and max guesses it took to guess the number and display them at the end of each game.
for the last part i have to base the game on a point system. I have to start the user out with 50 points per guess. each wrong answer will result in a loss of 75 points. each time the number is guessed, they will receive double the points given. ex: if you get 4 guesses, starting points are 200. winning points are 400.