"Heads or Tails" game I'm a beginner in programming and made a pretty simple heads or tails type game. I would like to know if I have done this efficiently. If not, please let me know what you would have done differently.

#include &lt;iostream&gt;
#include &lt;cstdlib&gt;
#include &lt;ctime&gt;
using namespace std;

void headsOrTails();
int randomNumber();

int main()
{
    headsOrTails();
}

int randomNumber()
{
    int number;
    srand(time(0));
    for(int i = 1; i &lt; 2; i++)
    {
        number = 1 + (rand()%2);
    }
    return number;
}

void headsOrTails()
{
    string prediction;
    cout &lt;&lt; "Heads or Tails? ";
    cin &gt;&gt; prediction;

    if((prediction == "Heads") || (prediction == "heads")){
        if(randomNumber() == 1){
            cout &lt;&lt; "Heads, you are correct!\n" &lt;&lt; endl;
        }
        else if(randomNumber() == 2){
            cout &lt;&lt; "Tails, you were wrong.\n" &lt;&lt; endl;
        }
    }
    if((prediction == "Tails") || (prediction == "tails")){
        if(randomNumber() == 1){
            cout &lt;&lt; "Heads, you were wrong.\n" &lt;&lt; endl;
        }
        else if(randomNumber() == 2){
            cout &lt;&lt; "Tails, you are correct!\n" &lt;&lt; endl;
        }
    }

    char playAgain;
    cout &lt;&lt; "Play again?(Y/N) ";
    cin &gt;&gt; playAgain;
    cout &lt;&lt; "\n";

    while((playAgain == 'Y') || (playAgain == 'y')){
        headsOrTails();
    }
    while((playAgain == 'N') || (playAgain == 'n')){
        exit(EXIT_FAILURE);
    }
}
Unnecessary loop

I noticed this code:


for(int i = 1; i &lt; 2; i++)
{
    number = 1 + (rand()%2);
}



It's a loop that loops exactly once, and it doesn't even use i inside the loop.  So you can just remove the loop part:

number = 1 + rand()%2;


Unecessary recursion

At the end of headsOrTails(), you have this code:


while((playAgain == 'Y') || (playAgain == 'y')){
    headsOrTails();
}
while((playAgain == 'N') || (playAgain == 'n')){
    exit(EXIT_FAILURE);
}




Each while here could really be an if.  Neither of the loops actually loop.
It's not a good practice use recursion for no reason.  Ideally, you would have a loop in main() that calls headsOrTails() as long as the user wants to keep playing.  That way, you wouldn't need recursion.  The only reason this even works instead of continuing indefinitely is because you call exit() eventually.
Why EXIT_FALURE?  That means your program will always return failure.  I would use EXIT_SUCCESS instead.