Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Can anyone help me write this code? The image is what the input should look like. Thank you! Write a program that starts a player

image text in transcribed

Can anyone help me write this code? The image is what the input should look like. Thank you!

Write a program that starts a player off with a bank of $15.00. A coin will flip and randomly choose heads or tails.The user will guess heads or tails to win. If the coin flip matches the player's guess his bet will be doubled. It costs 1 dollar to play and the program will bet that amount automatically each time as long as there is the available bank amount.

Note: Do not let the game begin if the user's bank amount is below $1.00. This is a large assignment. You should be using plenty of functions, random numbers, decision statements, the while loop(s) (not a do-while loop), unsigned variables, and i/o manipulation at a minimum.

At the end of the game, ask the user if he/she would like to play again and loop the game with bet input sequence again until the bank reaches 0.00 or the user inputs "n" to quit playing.

Here's a start to the code:

#include  #include  #include  using namespace std; char getDecision(); char getGuess(); char flipCoin(); void winOrLose(char g, char c, float & b); int main() { float bank = 15.00; char decision, guess, coin; // display the 3 lines of messages to user (or create another function for these cout statements) // call get decision // use a while loop and continue while the decision is y and the bank balance is >0 // the body of the while loop consist of 4 function calls.... // call getGuess // call flipCoin // call winOrLose // call getDecision // after the while loop, display the thank you message with the bank balance return 0; } char getDecision() { // the purpose of this function is to ask if the player wishes to play again // and return a y or n } char getGuess() { // the purpose of getGuess is to prompt the user to input h or t // and return the result } char flipCoin() { // the purpose of flipCoin is to generate a random number 1 or 2 // if it's 1, display the coin landed on heads and return h // if its a 2, display the coin landed on tails and return t } void winOrLose(char guess, char coin, float & bank) { // the purposse of this function is to determine if the player wins or loses // and adjust the bank accordingly // check for guess == coin and add logic to do the rest }
CAWINDOWS system32 cmd.exe elcome to the coin flip game It will cost 1 dollar to play If you guess correctly. you will match your bet one to one lould you like to play? (Y/N> uess heads or tails and I will tell you if you guessed correctly he coin landed on Tails our bank balance is :$14.00 lould you like to play again? (Y/N> uess heads or tails and I will tell you if you guessed correctly I am sorry, but you did not win this time. he coin landed on Tails OU WIN $2.00 our bank balance is :$16.00 lould you like to play again? (Y/N> hank you for playing. Your bank balance is $16.00 ress any key to continue

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Databases DeMYSTiFieD

Authors: Andy Oppel

2nd Edition

0071747990, 978-0071747998

More Books

Students also viewed these Databases questions

Question

Write down the circumstances in which you led.

Answered: 1 week ago