(Solved Homework): I have the following code, but it has lots of errors. please fix, thanks. //Include libraries #include

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

//Include libraries
#include <iostream>
#include <cstdlib>

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<<Micro casino”<<endl;

//desplaying message
cout<<“1) Flip a coin”<<endl;
cout<<“2) Roll dice for snake-eyes”<<endl;
cout<<“3) Permutaion of number of aces”<<endl;
cout<<“4) Factorial”<<endl;
cout<<“5) Quit”<<endl;
cout<<“Enter your choice”<<endl;

//store the choice
cin>>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<<endl;
}

else
{
break;
}

//pausing
system(“pause”);
}

//defining the method
int tossCoin()
{
cout<<“Enter a number “‘
cin>>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<<endl;
cout<<“Heads was tossed”<<heads<<“times”<<endl;
return rand () % 2;
}
int rollDice()
{
//declaring variables
int x;
cout<<“Enter a number”;
cin>>x;

//loop
for(int i=0; i<x; i++)
{
//computing the value
int dice1 = (int)(1+rand()%6));
int dice2 = (int)(1+(rand()%6));
diceSum= dice1 + dice2;
if(diceSum==2)
//update count
snakeEyes= snakeEyes+1;
}
cout<<“Number of snake eyes”<<snakeEyes<<“out of”<<x<<“throws”<<endl;
return snakeEyes;
}

int fact(int n)
{
fact1= 1;
for (int i= 1; i<= n; ++i)
{
fact1*=i;
}
return fact1;
}

int acesHand()
{
int aces;
aces =1 + rand() % 7;
int u = fact(7);
int v = fact(7-aces);
int perm = u/v;
cout<<“Number of permutations is”<<perm<<endl;
return perm;
}

————————————————————————————————————————

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 <iostream>

#include <stdlib.h>

#include <time.h>

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 <n (like randomNums(6) give 0 to 5, NOT 6).

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.

Expert Answer

 main.cpp:

 

#include <iostream>
#include <cstdlib>

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 << “Micro casino” << endl;

//desplaying message
cout << “1) Flip a coin” << endl;
cout << “2) Roll dice for snake-eyes” << endl;
cout << “3) Permutaion of number of aces” << endl;
cout << “4) Factorial” << endl;
cout << “5) Quit” << endl;
cout << “Enter your choice” << endl;

//store the choice
cin >> choice;
//if the choice is 1
if(choice==1)
{
tossCoin();
}
else if(choice==2)
{
rollDice();
}
else if(choice==3)
{
//call the method
acesHand();
}
else if(choice==4)
{
//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<<endl;
}
else
{
break;
}
}

//pausing
system(“pause”);
}

//defining the method
int tossCoin()
{
int coin;
cout << “Enter a number: “;
cin >> num;

heads = 0;

//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(coin ==1)
{
//update count
heads = heads +1;
}
}

//display new line
cout << endl;
cout << “Heads was tossed ” << heads << ” times out of ” << num << ” throws” << endl << endl;
return rand () % 2;
}

int rollDice()
{
//declaring variables
int x;
cout<<“Enter a number: “;
cin>>x;

snakeEyes = 0;

//loop
for(int i=0; i<x; i++)
{
//computing the value
int dice1 = (int)(1+rand()%6);
int dice2 = (int)(1+rand()%6);
diceSum= dice1 + dice2;

//update count
if(diceSum==2)
snakeEyes= snakeEyes+1;
}

cout << “Number of snake eyes ” << snakeEyes << ” out of ” << x << ” throws.” << endl << endl;
return snakeEyes;
}

int fact(int n)
{
fact1= 1;
for (int i= 1; i<= n; ++i)
{
fact1*=i;
}
return fact1;
}

int acesHand()
{
int aces;
aces =1 + rand() % 7;
int u = fact(7);
int v = fact(7-aces);
int perm = u/v;
cout<<“Number of permutations is”<< perm<<endl;
return perm;
}

Output:

iWriteHomework
Order NOW for a 10% Discount
Pages (550 words)
Approximate price: -

Why Us?

Top Quality and Well-Researched Papers

All ourbpapers are written from scratch. In fact, Clients who ask for paraphrasing services are highly discouraged. We have writers ready to craft any paper from scratch and deliver quality ahead of time.

Professional and Experienced Academic Writers

Our writers keeps you posted on your papers progress - providing you with paper outline/draft. You are also at liberty to communicate directly with your writer.

Free Unlimited Revisions

If you think we missed something, send your order for a free revision. You have 10 days to submit the order for review after you have received the final document. You can do this yourself after logging into your personal account or by contacting our support.

Prompt Delivery and 100% Money-Back-Guarantee

All papers are always delivered on time, in many cases quite ahead of time. In case we need more time to master your paper, we may contact you regarding the deadline extension. In case you cannot provide us with more time, a 100% refund is guaranteed.

Original & Confidential

We use several writing tools checks to ensure that all documents you receive are free from plagiarism. Our editors carefully review all quotations in the text. We also promise maximum confidentiality in all of our services.

24/7 Customer Support

Our support agents are available 24 hours a day 7 days a week and committed to providing you with the best customer experience. Get in touch whenever you need any assistance.

Try it now!

Calculate the price of your order

Total price:
$0.00

How it works?

Follow these simple steps to get your paper done

Place your order

Fill in the order form and provide all details of your assignment.

Proceed with the payment

Choose the payment system that suits you most.

Receive the final file

Once your paper is ready, we will email it to you.

Our Services

No need to work on your paper at night. Sleep tight, we will cover your back. We offer all kinds of writing services.

Essays

Essay Writing Service

No matter what kind of academic paper you need and how urgent you need it, you are welcome to choose your academic level and the type of your paper at an affordable price. We take care of all your paper needs and give a 24/7 customer care support system.

Admissions

Admission Essays & Business Writing Help

An admission essay is an essay or other written statement by a candidate, often a potential student enrolling in a college, university, or graduate school. You can be rest assurred that through our service we will write the best admission essay for you.

Reviews

Editing Support

Our academic writers and editors make the necessary changes to your paper so that it is polished. We also format your document by correctly quoting the sources and creating reference lists in the formats APA, Harvard, MLA, Chicago / Turabian.

Reviews

Revision Support

If you think your paper could be improved, you can request a review. In this case, your paper will be checked by the writer or assigned to an editor. You can use this option as many times as you see fit. This is free because we want you to be completely satisfied with the service offered.

× Contact Live Agents