Question

In C++ please Create a coin-flipping game. Ask the user how many times to flip the...

In C++ please

Create a coin-flipping game. Ask the user how many times to flip the coin, and use the random function to determine heads or tails each time a coin is flipped. Assume the user starts with $50. Every time the coin is flipped calculate the total (heads +$10, tails -$10). Create another function to test if the user has gone broke yet (THIS FUNCTION MUST RETURN A BOOLEAN TRUE/FALSE VALUE). End the program when the user is broke or when the coin was flipped the number of times the user had specified.

Display:

1) how many times the coin was flipped,

2) the number of times “heads” was the result,

3) the number of times “tails” was the result, and

4) how much money the user has at the end

0 0
Add a comment Improve this question Transcribed image text
Answer #1

// C++ code

#include <iostream>

#include <fstream>

#include <string>

#include <iomanip>

#include <stdio.h>

#include <stdlib.h>

using namespace std;

// unction to test if the user has gone broke yet (THIS FUNCTION MUST RETURN A BOOLEAN TRUE/FALSE VALUE)

bool checkheadtail()

{

// check head

if(rand()%2==0)

return false;

// else tail

return true;

  

}

int main()

{

srand(time(NULL));

int countflip;

int countHead = 0;

int tails = 0;

int bet = 50;

cout << "Enter how many times coin should flip: ";

cin>>countflip;

  

for(int i=0 ; i<countflip;++i)

{

// (heads +$10, tails -$10)

if(!checkheadtail())

{

bet = bet + 10;

countHead = countHead + 1;

}

else

{

bet = bet - 10;

tails = tails +1;

}

}

cout<<"Total times Coins flipped : "<<countflip<<endl;

cout<<"Number of times 'heads': "<<countHead<<endl;

cout<<"Number of times 'tails': "<<tails<<endl;

cout<<"Money: $"<<bet<<endl;

return 0;

}

Terminal E : E ®(1:30, 85%) ») 10:48 PM ubuntu new.py Solution javax soluton.cpp Х input.txt HomeworkLib.cpp main.c HomeworkLib.pyx cheg

Add a comment
Know the answer?
Add Answer to:
In C++ please Create a coin-flipping game. Ask the user how many times to flip the...
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
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