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.
Put the code you need help with here.
#include <iostream>
#include <cstdlib>
#include <ctime>
usingnamespace 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;
}
elseif (diff >=50)
{
cout << "Your guess is very high , go lower!" << endl << endl;
}
elseif (diff >= 20)
{
cout << "Your guess is high, go lower!" << endl << endl;
}
elseif (diff <=-50)
{
cout << "Your guess is way to low , go higher !" << endl << endl;
}
elseif (diff <= -20)
{
cout << "Your guess is low , go higher!" << endl << endl;
}
elseif (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;
}
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;
}