1 2
|
cout << "If you guess correctly, you will win $2.00" << endl;
cout << "If you guess correctly, you will match your bet one to one." << endl;
|
What if you guess incorrectly? I think you want the second line to say "If you guess incorrectly, you will lose your bet."
1 2 3 4 5 6 7
|
if (guess == computer_throw) {
cout << "You win\n";
winnings = 2.00;
} else {
cout << "You lost\n";
winnings = -2.00;
}
|
Losing costs you your $1 bet, not $2.
Write a program that starts a player off with a bank of $15.00 |
Your program starts the player with $14.
You ask if they want to play once, at the beginning of the program. The first bet should happen automatically and then you ask if they want to play again.
You have
num = rand() % 2
in three different places. You only need it once.
You should be using plenty of functions [...] unsigned variables .... |
I see no functions or unsigned variables.
Here are some ideas for functions:
intro() - displays the introductory text.
getGuess() - prompt the user for their guess. Read it and convert to upper case. Return 'H' or 'T'
playAgain() - ask user if they want to play again and read response. Return true or false, depending on whether they want to play again.
playOnce() - Flip the coin, Get the guess, and display the results. Returns the winnings.
With these functions, the man function becomes:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
|
int
main()
{
double bank = 15.00;
bool again = true;
srand(time_t(NULL));
intro();
while (again && bank >= 1.00) {
cout << "Your bank balance is $" << bank << endl;
bank += playOnce();
again = playAgain();
}
return 0;
}
|