#include <iostream>
#include <cstdlib>
#include <ctime>
usingnamespace std;
int main (void)
{
int AskRange;
int GetMagicNumber = rand() % AskRange + 1;
int Guess;
int tries = 0;
char PlayAgain;
cout << " Please enter the top number of the range(Must be a number greater than 0) \n";
cin >> AskRange;
if ( AskRange > 0 )
{
cin >> AskRange;
}
else
{
cout << " Please enter a value that is greater than zero \n";
cin >> AskRange;
}
srand(time(NULL));
while (true)
{
cout << " Enter a Number between 0 and " << AskRange << " ( " << 5 - tries << " tries left): \n";
cin >> Guess;
cin.ignore();
if ( Guess > GetMagicNumber)
{
cout << " Too high! Try again.\n";
}
elseif ( Guess < GetMagicNumber )
{
cout << " Too Low! Try Again.\n";
}
else
{
break;
}
tries++;
}
if (tries >= 5)
{
cout << " You ran out of tries!\n";
}
else
{
cout << " Congratulations!! " << endl;
cout << " You got the right number in " << tries << "tries!\n";
}
while (true)
{
cout << " would you like to play again? ( Y/N)?" ;
cin >> PlayAgain;
cin.ignore();
if ( PlayAgain == 'N' || PlayAgain == 'n' || PlayAgain == 'y' || PlayAgain == 'Y' )
{
break;
}
else
{
cout << " Please enter \'Y'\ or \ 'N'\ . . . \n";
}
}
if ( PlayAgain == 'n' || PlayAgain == 'N' )
{
cout << "Thanks for playing!";
break;
}
cout << "Enter anything to exit. . . \n";
cin.ignore();
return(0);
}
EDIT**
Im getting so many errors, idk if i should post them all.
Hello! Looks like you're missing some syntactical things, they're easy to mess up when you're first starting. Some things to get you started.
1. make sure you have the >> operator after cin pointing the right direction every time
2. make sure cin.ignore is spelled right
3. make sure you declare all of your variables before using them (especially the guess variable)
4. you have an extra } somewhere near the end of your code
5. endl has an L at the end, not a 1
C++ is case sensitive so guess and Guess are different and guess is undeclared while Guess is undefined oh and error checking with an if statement may not be as good as using a loop