#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;
}
#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;
if (headsortails == zeroOne)
{
cout << "Winner, the coin came up " << zeroOne << endl;
bankTotal = 10 + 2;
}
if (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;
}
What do you think this line if (headsortails == zeroOne) is doing? zeroOne is going to be either 0 or 1. headsortails will be whatever character the user entered at the prompt. It looks like you're suggesting 'h' or 't', but even if the user put in '0' or '1' the condition would fail anyway. '0' is not the same as 0. One is a character, the other is a number. Think about the input you're getting from the user and what you want to compare it to.