Guessing game!

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.


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
//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!
Last edited on
You need to use a while loop...try to add it to your code first, then if you have problems, post again.
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.
Last edited on
Topic archived. No new replies allowed.