help with guessing game

Write your question here.

hey guys for some reason everytime I use this program it messes up it doesn't show the messages as I have them there and theres 2 more steps that I do not know how to do which are keeping track of highscores and saving the highscores to a text file. any help will be greatly appreciated.

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
  Put the code you need help with here.
#include <iostream>
#include <cstdlib>
#include <ctime>

using namespace std;

int main()
{
int highscores;
	int diff; //difference between random number and your guess.
	int tries = 0;
    int num; // holding a random number generated by computer
    int guess; // holds the guess of the user
    bool isGuessed; // true if user guessed the number correctly
    srand(time(0)); // initialize randomness with time
    num = rand() % 100; // ensure the number is 0 to 100

    isGuessed = false;
	

    cout << "I have a number between 0 and 100. Try to guess what it is." << endl << endl;

    while (!isGuessed)
  {
        cout << "So, what is your guess? ";
        cin >> guess;
	 	diff = num - guess;
		tries = tries ++;
        if (diff == 0)
        {
           cout << "Phew... You got it!! in tries " << tries << endl;
           isGuessed = true;
        }
        else if (diff >=50)
        {
           cout << "Your guess is very high , go lower!" << endl << endl;
        }
        else if (diff >= 20)
        {
           cout << "Your guess is high, go lower!" << endl << endl;
        }
		        else if (diff <=-50)
        {
           cout << "Your guess is way to low , go higher !" << endl << endl;
        }
        else if (diff <= -20)
        {
           cout << "Your guess is low , go higher!" << endl << endl;
        }
	 else if (diff >= 20 && diff <= 50)
        {
           cout << "Your close to the number" << endl << endl;
        }
		if ( tries > 5 )
		{
			cout<<"Game over - You failed to guess the number";
			break;
		}

	}
    system("PAUSE");
    return 0;
}
else if (diff >= 20 && diff <= 50)
Should it be -20, not 20?

Also, line 29 should be just tries++; or ++tries;.
how can I write something for highscore which is least amount of tries to guess and save that to a txt file
#include <iostream>
#include <cstdlib>
#include <ctime>

using namespace std;

int main()
{
int highscore;
int diff; //difference between random number and your guess.
int tries = 0;
int num; // holding a random number generated by computer
int guess; // holds the guess of the user
bool isGuessed; // true if user guessed the number correctly
srand(time(0)); // initialize randomness with time
num = rand() % 100; // ensure the number is 0 to 100

isGuessed = false;


cout << "I have a number between 0 and 100. Try to guess what it is." << endl << endl;

while (!isGuessed)
{
char answer;
cout << "So, what is your guess? ";
cin >> guess;
diff = num - guess;
highscore = tries;
tries = tries++;
if (diff == 0)
{
cout << "Phew... You got it!! in tries " << tries << endl;
isGuessed = true;
}
else if (diff >=50)
{
cout << "Your guess is very low , go higher!" << endl << endl;
}
else if (diff >= 20)
{
cout << "Your guess is low, go higher!" << endl << endl;
}
else if (diff <=-50)
{
cout << "Your guess is way to high , go lower !" << endl << endl;
}
else if (diff <= -20)
{
cout << "Your guess is high , go lower!" << endl << endl;
}
else if (diff >= -20 && diff <= 50)
{
cout << "Your close!" << endl << endl;
}
if ( tries > 5 )
{
cout << "They highscore is" << highscore - tries << endl;
cout<<"Game over - You failed to guess the number... Play again?[y/n]";
cin >> answer;
if (answer!='n')
{
isGuessed=false;
//break;
}
else
{
break;
}


}


}
return 0;
}
Topic archived. No new replies allowed.