For this project, I am creating a coin flip game. It will ask the user to input Heads (H) or Tails (T). If they guess correctly they will win $2. If incorrect -$1. I am having trouble with the random number generator. I want to convert the numbers it outputs to either Heads or Tails.
#include <iostream>
#include <ctime>
usingnamespace std;
int main()
{
char answer;
double bankTotal = 10;
int zeroOne;
char headsortails;
int Heads = 0;
int Tails = 1;
srand(static_cast<unsignedint>(time(0)));
zeroOne = rand() % 2;
cout << "Welcome to the coin flip game. It cost a dollar to play. " << endl;
cout << "If you guess correctly you will win $2.00" << endl;
cout << "Do you want to play (y/n)? " << endl;
cin >> answer;
while (toupper(answer) == 'Y')
{
cout << "Your bank is $" << bankTotal << endl;
cout << "Enter heads or tails (h/t)" << endl;
cin >> headsortails;
while (headsortails == zeroOne)
{
cout << "Winner, the coin came up " << zeroOne << endl;
bankTotal = 10 + 2;
}
while (headsortails != zeroOne)
{
cout << "Sorry, you loose. The coin flip came up " << zeroOne << endl;
bankTotal = 10 - 1;
}
cout << "Would you like to play again (y/n)? " << endl;
}
cout << "Thanks for playing, your bank is $" << bankTotal << endl;
cout << "Please come again " << endl;
return 0;
}