Question
(Microsoft Visual Source, C++, Course: CIS-5, Intro to Programming)
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 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.

It should look like the following:

Eİ CAWINDOWSSystem32cmd.exe Welcone to the coin flip game. It will cost 1 dollar to play If you guess correctly. you will mat
0 0
Add a comment Improve this question Transcribed image text
Answer #1

//C++ program

#include<iostream>
#include<stdlib.h>
#include<time.h>
using namespace std;

int main(){
   cout<<"Welcome to the coin flip game.\n";
   cout<<"It will cost 1 dollar to play\n";
   cout<<"If you guess correctly .you will match your bet one to one\n\n";
  
   srand(time(NULL));
   double bank_amount = 15;
   char choice,toss,randomtoss;
   cout<<"Would you like to play? (y/n) : ";
   cin>>choice;
  
   while(choice=='y'||choice=='Y'&& bank_amount>=1){
       randomtoss = rand()%2==1?'h':'t';
       cout<<"\nGuess head or tail and i will tell you if you guessed correctly (h/t) : ";
       cin>>toss;
      
       if(randomtoss=='h')cout<<"The coin landed on Heads\n";
       else cout<<"The coin landed on Tails\n";
      
       if(randomtoss==toss){
           cout<<"YOU WIN $2.00\n";
           bank_amount+=2;
       }
       else{
           cout<<"I am sorry , you did not win this time\n";
           bank_amount-=1;
       }
       cout<<"Your bank balance is :$"<<bank_amount<<"\n";
       cout<<"Would you like to play? (y/n) : ";
   cin>>choice;
   }
  
   cout<<"Thank You for Playing . Your bank balance is $"<<bank_amount<<"\n";
   return 0;
}

//sample output

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 ould y

Add a comment
Know the answer?
Add Answer to:
(Microsoft Visual Source, C++, Course: CIS-5, Intro to Programming) Write a program that starts a player...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • A simple game of chance Using a while loop write a simple coin flip game. Specifics:...

    A simple game of chance Using a while loop write a simple coin flip game. Specifics: The user starts with a bank of $10.00 It costs a dollar to play A correct guess pays $2.00 The while loop is used for the game loop. It should ask if the user wants to play. The while loop will check for a value of 'Y' or 'N'. You should also allow for lower case letters to be input. You MUST prime the...

  • Please help with this Intro to programming in C assignment! Intro to Programming in C-Large Program...

    Please help with this Intro to programming in C assignment! Intro to Programming in C-Large Program 3 - Hangman Game Assignment purpose: User defined functions, character arrays, c style string member functions Write an interactive program that will allow a user to play the game of Hangman. You will need to: e You will use four character arrays: o one for the word to be guessed (solution) o one for the word in progress (starword) o one for all of...

  • Create a new program, WordGuessingGame. Using a while loop, create a game for the user. The...

    Create a new program, WordGuessingGame. Using a while loop, create a game for the user. The game requires the user to guess a secret word. The game does not end until the user guesses the word. After they win the game, they are prompted to choose to play again. The secret word that user must guess is "valentine". It is a case-sensitive analysis With each guess... If the guess does not have an equal number of characters, tell the user...

  • c++ Program 2: Coin Toss Simulator For this program, please implement Problems 12 and 13 in...

    c++ Program 2: Coin Toss Simulator For this program, please implement Problems 12 and 13 in a single program (Gaddis, p812, 9E). Scans of these problems are included below. Your program should have two sections that correspond to Problems 12 and 13: 1) As described in Problem 12, implement a Coin class with the specified characteristics. Run a simulation with 20 coin tosses as described and report the information requested in the problem. 2) For the second part of your...

  • Write a game application that generates a random number between 1 and 1000 (inclusive) and prompts...

    Write a game application that generates a random number between 1 and 1000 (inclusive) and prompts the user for a guess. Use the pseudorandom number generator, the Random class. When the user guesses the correct number, say so, and display how many guesses the user required to guess correctly. Allow the user to play multiple times by asking the user if the user wants to continue playing.      Guess my number between 1 and 1000 => 500      Too high...

  • Write a program that simulates the toss of a coin. Whenever a coin is tossed the...

    Write a program that simulates the toss of a coin. Whenever a coin is tossed the result will be either a head or tail. Prompt the user as shown by entering an ‘H’ for heads or ‘T’ for tails. Use a loop for input validation of an ‘h’ or ‘t’. Make sure that both an upper case and lower case will be accepted. Have the computer generate a random number. Assign a char variable a (‘h’ ^ ’t’) head or...

  • Write a JAVA program that plays a number guessing game with the user. A sample run...

    Write a JAVA program that plays a number guessing game with the user. A sample run for the game follows. User input is shown in boldface in the sample run. Welcome to the game of Guess It! I will choose a number between 1 and 100. You will try to guess that number. If your guess wrong, I will tell you if you guessed too high or too low. You have 6 tries to get the number. OK, I am...

  • Lab #6 Number Guessing Game – Loops and Nested Loops Requirements: Design, develop, test, and submit a program for a Number Guessing game. The program will select a random number between 0 and 100, al...

    Lab #6 Number Guessing Game – Loops and Nested Loops Requirements: Design, develop, test, and submit a program for a Number Guessing game. The program will select a random number between 0 and 100, allow the user to try up to 10 times to guess the number, and tell the user if each guess is too high, too low, or correct. The actual game portion must be a function...you can use more than one function in your program. The amount...

  • Please write a C# program that where a player will play a guessing game with the...

    Please write a C# program that where a player will play a guessing game with the range of 1-100. Each time the play guesses a number, and it is not correct the program should indicate if the number is more or less than what the player guessed. The play should be able to guess until the correct number has been guessed. If an invalid number is entered, such as: 1.24 (real number), or asd (string). The program should tell user...

  • This program will implement a simple guessing game... Write a program that will generate a random...

    This program will implement a simple guessing game... Write a program that will generate a random number between 1 and 50 and then have the user guess the number. The program should tell the user whether they have guessed too high or too low and allow them to continue to guess until they get the number or enter a 0 to quit. When they guess the number it should tell them how many guesses it took. At the end, the...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT