Question
Consider the following main function of a C++ program named coingame.cpp, which is missing the function definitions for coinflip()and coingame(): #include #include #include #include #include
Consider the following main function of a C++ program named coingame.cpp, which is missing the function definitions for coinflip()and coingame():
#include #include #include #include #include using namespace std;
bool coinflip(); double coingame();
const double GAME_COST = 5.50;
int main() { char chUser; double payment = 0;
srand(time(0));
cout
cout
for (int i = 0; i
cout > chUser;
while (toupper(chUser) == 'Y') { payment -= GAME_COST;
cout
payment += coingame();
cout > chUser; } cout
if (payment
return 0; }
//ADD YOUR FUNCTION DEFINITIONS HERE
/* ADD YOUR SAMPLE EXECUTIONS HERE
*/
Define the coinflip()and coingame()functions.
You may NOT change the given main function!
Sample output:
Another sample output:
I tried to finish it myself, here's my code as well as sample outputs. This was all the information my professor gave to me.
#include#include #include #include #include using namespace std; bool coinflip(); double coingame(); const double GAME_COST = 5.50; int main() { char chUser; double payment = 0; srand(time(0)); cout > chUser; while (toupper(chUser) == 'Y') { payment -= GAME_COST; cout > chUser; } cout cd "c:\Users\smith\Downloads\" ; if ($?) { g++ HW07_coingame_template.cpp -o HW07_coingame_template } ; if ($?) { .\HW07_coingame_template } Welcome to Crunchum's Coin Flip Game! Here's a 10-Flip Example (T = Tails, H = heads): TTHHHHHHTT Look's like a fair coin to me! Each game costs $5.50, would you like to play a game? y We'll flip a coin until the first Head appears, on the nth flip. Your payment will be (2^(n-2))$. Game Results: H Your current balance is: -5.00 Would you like to play another game for 5.50? y We'll flip a coin until the first Head appears, on the nth flip. Your payment will be (2^(n-2))$. Game Results: TTTH Your current balance is: -10.00 Would you like to play another game for 5.50? n Thanks for playing! Don't forget to pay your balance of $10.00 */
I believe the output I'm getting is somehow wrong.
Welcome to Crunchum's Coin Flip Game! Here's a 10-Flip Example (T-Tails, H -heads): HHHHHHTHHT Look's like a fair coin to me! Each game costs $5.50, would you like to play a game? y We'll flip a coin until the first Head appears, on the nth flip. Your payment will be (2^(n-2 )) $ Game Results: H Your current balance is: -5.00 Would you like to play another game for 5.50? y We'll flip a coin until the first Head appears, on the nth flip. Your payment will be (24 (n-2))$ Game Results: H Your current balance is: -10.00 Would you like to play another game for 5.50? in Thanks for playing! Don't forget to pay your balance of $10.00 Welcome to Crunchum's Coin Flip Game! Here's a 10-Flip Example (TTails, Hheads): THHTTHHHHH Look's like a fair coin to me! Each game costs $5.50, would you like to play a game? y We'll flip a coin until the first Head appears, on the nth flip. Your payment will be (2 (n-2))s. Game Results: TTTTTH Your current balance is: 10.50 Would you like to play another game for 5.50? y We' flip a coin until the first Head appears, on the nth flip. Your payment wi1l be (2 (n-2)) Game Results: TTTTH Your current balance is: 13.00 Would you like to play another game for 5.50? n Thanks for playing! Congratulations on your winnings of $13.00
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started