Question

I am trying to program a dice game in Visual Studios c++ but am having trouble....

I am trying to program a dice game in Visual Studios c++ but am having trouble. The program allows the user to choose the number of rolls, not exceeding 100,000. I am trying to print out the number of times each number(1-6) was rolled, but it's not working. What am I doing wrong? The link below is a copy of my code.

https://docs.google.com/document/d/1baKfnof4pjdQ4905hwXluFtbcA1Fs7QESMQKy45xdpE/edit

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

#include <iostream>
#include <cstdlib>   
#include <ctime>
using namespace std;

int main()
{
int n;
int dice[6] = {0,0,0,0,0,0};
srand (time(NULL));
cout<<"Enter the number of rolls: "<<endl;
cin >> n;
for(int i=0; i<n;i++) {
int roll = rand() % 6 + 1;
dice[roll-1]++;
}
for(int i=0;i<6;i++) {
cout<<"The number of times each number "<<(i+1)<<" was rolled: "<<dice[i]<<endl;
}
return 0;
}

Output:

$g++ -std=c++11 -o main *.cpp
$main
Enter the number of rolls: 
The number of times each number 1 was rolled: 185
The number of times each number 2 was rolled: 138
The number of times each number 3 was rolled: 173
The number of times each number 4 was rolled: 168
The number of times each number 5 was rolled: 178
The number of times each number 6 was rolled: 158
Add a comment
Know the answer?
Add Answer to:
I am trying to program a dice game in Visual Studios c++ but am having trouble....
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
  • I am having some trouble writing this program. In C language Write a program which asks...

    I am having some trouble writing this program. In C language Write a program which asks user 1) number of sets (integer input), followed by 2) number of sides of a dice (integer input) and 3) number of dices (integer input). number of sets mean how many times this process is going to repeat, number of sides mean total number of sides in a dice (usually 6) and number of dices mean how many number of dices we’re going to...

  • I'm using visual studios ASP.net with C# and I'm having trouble doing theses conversions. To convert...

    I'm using visual studios ASP.net with C# and I'm having trouble doing theses conversions. To convert a text date to a DateTime object, use the Convert.ToDateTime method. To get the number of nights, you can subtract the departure date from the arrival date and then use the Days property of the resulting TimeSpan object. To convert a selection in the drop-down list for the number of people to an integer, use the Convert.ToInt32 method.

  • can someone help me fix my jeopardy dice game I am having a hard time figuring...

    can someone help me fix my jeopardy dice game I am having a hard time figuring out what i am doing wrong #include #include using namespace std; //this function makes a number between 1 and 6 come out just like a dice int rollDie() { return (rand() % 6+1); } //this function asks the user with a printed statement if they want to roll the dice and gives instructions for yes and no (y/n) void askYoNs(){ cout<<"Do you want to...

  • Write a c++ program that simulates a million of games in craps. I am having a...

    Write a c++ program that simulates a million of games in craps. I am having a trouble getting to loop a million of times. I am trying to use a const for a million. This is the code so far. #include <iostream> #include <cstdlib>// contains prototypes for functions srand and rand #include <ctime>// contains prototype for function time #include <iomanip> using namespace std; int rollDice(); // rolls dice, calculates and displays sum void printstats(); int totroll = 0, games, point,...

  • I need help figuring out how to code this in C++ in Visual Studio. Problem Statement:...

    I need help figuring out how to code this in C++ in Visual Studio. Problem Statement: Open the rule document for the game LCR Rules Dice Game. Develop the code, use commenting to describe your code and practice debugging if you run into errors. Submit source code. Use the document to write rules for the user on how to play the game in a text file. Then, using the information from the resource articles, create a program that will read...

  • Help about c++ assignment, the due date was very soon right now

    I am still struggling to do this assignment using c++ visual studios right now, i need help before the deadlineThe questions are in the google docs and I need help now because the due date was very soon at the 30th of November 2021 so I need help as soon as possible about the program on visual studios c++ and make the program quick before the due date right now.Now I got 11 people request to get the answer on...

  • Java programming Write a simulation of the Craps dice game. Craps is a dice game that...

    Java programming Write a simulation of the Craps dice game. Craps is a dice game that revolves around rolling two six-sided dice in an attempt to roll a particular number. Wins and losses are determined by rolling the dice. This assignment gives practice for: printing, loops, variables, if-statements or switch statements, generating random numbers, methods, and classes. Craps game rules: First roll: The first roll (“come-out roll”) wins if the total is a 7 or 11. The first roll loses...

  • I have answered part I but I am having trouble with part II. I am providing...

    I have answered part I but I am having trouble with part II. I am providing part I so all the information is listed but part I is not what I need help with. How do you play two dice Bunco? There are six rounds, one for each of the possible outcomes in a die, namely the numbers one through six. Going clockwise, players take turns rolling two dice trying to score points. Points are usually awarded as such: 21...

  • Please i need helpe with this JAVA code. Write a Java program simulates the dice game...

    Please i need helpe with this JAVA code. Write a Java program simulates the dice game called GAMECrap. For this project, assume that the game is being played between two players, and that the rules are as follows: Problem Statement One of the players goes first. That player announces the size of the bet, and rolls the dice. If the player rolls a 7 or 11, it is called a natural. The player who rolled the dice wins. 2, 3...

  • I need trying to figure out how I can make create a code in Python with this exercise for I am having trouble doing so. Miles Per Gallon Calculator Write a GUI program that calculates a car's gas...

    I need trying to figure out how I can make create a code in Python with this exercise for I am having trouble doing so. Miles Per Gallon Calculator Write a GUI program that calculates a car's gas mileage. The program's window should have Entry widgets that let the user enter the number of gallons of gas the car holds, and the number of miles it can be driven on a full tank. When a Calculate MPG button is clicked,...

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