Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I have the following code, but it has lots of errors. please fix, thanks. //Include libraries #include #include using namespace std; //declare method int tossCoin();

I have the following code, but it has lots of errors. please fix, thanks.

//Include libraries #include #include using namespace std; //declare method int tossCoin(); int rollDice(); int fact(int n); int acesHand(); //declare variables int diceSum, snakeEyes=0, num= 0, counter, tails = 0, heads= 0, choice= 0; int n, fact1= 1; //defining main method int main() { //this will loop until the user quits while (choice!=5) { cout<>choice; //if the choice is 1 if(choice==1) { tossCoin(); } else if(choice==2) { rollDice(); } else if(choice==3) { //call the method acesHand(); } //displaying the messege cout<< "Enter a positive integer please: "; //store the value cin >> n; int res = fact(n); //displaying the messege cout << "Factorial of " << n << " = " << res<>num; //loop for (counter =1; counter <= num; counter++) { //toss the coin coin= rand () % 2; //if the value is 0 if (coin == 0) { //update the count tails = tails + 1; } //if value is 1 else if(coint ==1) { //update count heads = heads +1; } } //display new line cout<>x; //loop for(int i=0; i

the instructions were:

Create a Micro casino that will either flip a coin, roll dice for snake-eyes, or do a permutation of number of aces.

tossCoin , will take a positive integer and flip the coin, count the number of heads and return the number of heads.

rollDice, will take a positive number, roll two dice (values from 2 to 12) and return the number of snake-eyes (value of 2).

factorial, take a positive number and return its factorial (there are several examples of factorial).

acesHand, given that you have 7 aces in your hand, how many ways can you select X number of aces from that hand (permutations, pass the X number to the function and X has to be in range of 1 to 7).

You need the random number generator for the tossCoin and rollDice.

For C++, include:

#include

#include

#include

Then in main as one of the first statements, set the seed like:

srand(time(NULL));

Note: you do the srand ONLY once! Then use the rand() to get the random number (can rand multiple times).

For Java, do:

import java.util.Random;

And in main, do:

Random randNums = newRandom();

Then to get a random number you do:

int rand = randomNums.nextInt(n);

Where n is an integer value to go from 0 to

A sample run would look like:

Micro casino

1) flip a coin

2) roll dice for snake-eyes

3) permutation of number of aces

0) quit: 2

Number of snake-eyes 7 out of 101 throws

Micro casino

1) flip a coin

2) roll dice for snake-eyes

3) permutation of number of aces

0) quit:

Note: use a prime number (constant) as the number of tosses to pass to either flip a coin or roll dice for snake eyes.

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

Marketing Database Analytics

Authors: Andrew D. Banasiewicz

1st Edition

0415657881, 978-0415657884

More Books

Students also viewed these Databases questions

Question

=+j Describe the various support services delivered by IHR.

Answered: 1 week ago