Hi, I want to call again() from game(), it works on windows but not on mac. When I call it, it says again() is not defined, so I put it before game. Now game() isn't defined. Is there anyway to make this mac compatible?
Code:
#include <cstdlib>
#include <ctime>
#include <iostream>
int again()
{
using std::cout;
using std::cin;
using std::endl;
cout << "Play again? Y/N ";
char again;
cin >> again;
if (again == 'y' || again == 'Y')
{
game();
}
else
{
return 0;
}
}
int game()
{
using std::cout;
using std::cin;
using std::endl;
srand((unsigned)time(NULL));
int randomnum, difficultnumber, number;
randomnum = rand()%1001;
char difficulty;
cout << "Difficulty\n[E]asy (15 guesses) [N]ormal (10 guesses) or [H]ard (5 guesses)?: ";
cin >> difficulty;
if (difficulty == 'e' || difficulty == 'E')
{
difficultnumber = 15;
cout << "Easy." << endl << endl << "You have " << difficultnumber << " guesses left.";
}
else
{
if (difficulty == 'n' || difficulty == 'N')
{
difficultnumber = 10;
cout << "Normal." << endl << endl << "You have " << difficultnumber << " guesses left.";
}
else
{
if (difficulty == 'h' || difficulty == 'H')
{
difficultnumber = 5;
cout << "Hard." << endl << endl << "You have " << difficultnumber << " guesses left.";
}
}
}
while (difficultnumber > 0)
{
cout << "\nGuess a number between 1 and 1000: ";
cin >> number;
if (number == randomnum)
{
cout << "You won in " << difficultnumber << " guesses!\n";
again();
}
if (number > randomnum)
{
cout << "Too High.";
difficultnumber--;
if (difficultnumber == 0)
{
cout << endl << "\nSorry, but you have lost. The number was " << randomnum << ".\n";
again();
}
else
{
cout << "\nYou have " << difficultnumber << " guesses left.\n";
}
}
if (number < randomnum)
{
cout << "Too Low.";
difficultnumber--;
if (difficultnumber == 0)
{
cout << endl << "\nSorry, but you have lost. The number was " << randomnum << ".\n";
again();
}
else
{
cout << "\nYou have " << difficultnumber << " guesses left.\n";
}
}
}
}
int main()
{
game()
return 0;
}
Thank you,