Random number game issues

I need my code to display certain messages after it states you won depending on how many guesses it took the user to get it right.
guesses < 4 "Either you know my secret or you got lucky"
guesses >= 5 || guesses <= 7 "You're pretty good at this"
guesses >= 8 || guesses <= 10 "You'll do better next time"

If anyone could help I would appreciate it. Thank you!

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
//This program generates a random number between 1 and 100.
//The user gets to try and guess the number.
//Will you guess the number?
#include <iostream>
#include <time.h>
#include <string>
using namespace std;

int main()
{
	int guesses = 10, guess, answer;

	srand(time(NULL));
	answer = rand() % 100 + 1;

	cout << "Ready to play the guessing game?\n";
	cout << "Can you guess the number I'm thinking of between 1 and 100, before you\nrun out of guesses?\n\n";

	for (int i = 0; i < guesses; i++)
	{
	   	cout << "Guess the number I am thinking: ";
		cin >> guess;

	    if (guess < 1 || guess > 100)
			cout << "Invaild guess please pick a number 1-100.\n";

		else if (guess != answer)
		{
			if ( guess > answer)
				cout << "To high! try again.\n";
			else 
			    cout << "To low! try again.\n";
		}	
		else
		{
			cout << "You won!!\n";
		}
		
         }
    cout << "Sorry - you have taken to many guesses";

	system("pause");
	return.0;
}
The first thing you need to do is break out of the loop when the correct guess is made, Then if your loop counter (i) was declared before the loop you could use that variable to tell how many guesses they made before they got it correct.



Topic archived. No new replies allowed.