My program is almost finished but has a slight mishap that I need to fix but don't know how to. Variable coin_flip produces a 1 or 0, but i need to convert them to output 'Heads' or 'Tails'.
#include <iostream>
#include <ctime>
usingnamespace std;
int main()
{
char answer;
double bankTotal = 10;
int coin_flip;
char headsortails;
srand(static_cast<unsignedint>(time(0)));
coin_flip = 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 (toupper(headsortails == coin_flip))
{
cout << "Winner, the coin came up " << coin_flip << endl;
bankTotal = bankTotal + 2;
}
while (toupper(headsortails != coin_flip))
{
cout << "Sorry, you loose. The coin flip came up " << coin_flip << endl;
bankTotal = bankTotal - 1;
break;
}
cout << "Would you like to play again (y/n)? " << endl;
cin >> answer;
}
cout << "Thanks for playing, your bank is $" << bankTotal << endl;
cout << "Please come again " << endl;
return 0;
}