Question

Problem: Write a C program that simulates a die with six faces. The program is rolling...

Problem:

Write a C program that simulates a die with six faces.

The program is rolling the die for the user, but the user needs to specify how many times the die needs to be rolled.

Have the program print out how many times a certain face came up, along with the percentage out of 100%.

Homework Answers

Answer #1

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#define DICE_SIDES 6
int main(void)
{
int dice_side[DICE_SIDES]={0};
int i,NUMBER_ROLLS;   
printf("Enter no of Rolls\n");
scanf("%d",&NUMBER_ROLLS);
for (i = 0; i < NUMBER_ROLLS; i++) {
dice_side[rand() % DICE_SIDES]++;
}
printf("Sides\tNo of times\tPercentage\n");
for (i = 0; i < DICE_SIDES; i++){
int noOfTimes=dice_side[i];
printf("%d\t %d \t \t%d \n", i,noOfTimes ,noOfTimes*100/NUMBER_ROLLS);
}
return 0;
}

output:

Know the answer?
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
Similar Questions
Python Practice Sample: Write a program to simulate rolling a 6-sided die until the sum of...
Python Practice Sample: Write a program to simulate rolling a 6-sided die until the sum of the numbers rolled is equal to or greater than 21. If it is exactly 21, print “You won!”; if it is more than 21, print “You lost!.” Show the number rolled and the accumulated total each time. Number rolled: 6. Your total is now: 6. Number rolled: 6. Your total is now: 12. Number rolled: 4. Your total is now: 16. Number rolled: 1....
Two faces of a six-sided die are painted red, two are painted blue, and two are...
Two faces of a six-sided die are painted red, two are painted blue, and two are painted yellow. The die is rolled three times, and the colors that appear face up on the first, second, and third rolls are recorded. (a) Let BBR denote the outcome where the color appearing face up on the first and second rolls is blue and the color appearing face up on the third roll is red. Because there are as many faces of one...
A game involves rolling a fair six-sided die. If the number obtained on the die is...
A game involves rolling a fair six-sided die. If the number obtained on the die is a multiple of three, the player wins an amount equal to the number on the die times $20. If the number is not a multiple of three, the player gets nothing. How will you model the simulation for the roll of a die? A. Use the numbers 1–20 to represent the numbers rolled when a player wins. B. Use the numbers 1–6 to represent...
Design an application that uses the C# random generator to randomly roll a six face dice...
Design an application that uses the C# random generator to randomly roll a six face dice ( no 1 - no 6) . If the user rolled a 3, the user gets to roll the six face die again. You must use a switch statement to write the result /s of the random dice roll/s to the screen. Hint: You should have nested switches in your program
1)Write a program that asks a user for a number. If (and only if) the number...
1)Write a program that asks a user for a number. If (and only if) the number is greater than zero print “The number is valid” 2)Write a program that asks a user for a grade. If (and only if) the grade is greater than zero and less than 101, print “The grade is valid” 3)Write a program that asks a user how many widgets they want to buy and prints out what the user should pay. Widgets costs 10 dollars....
IN JAVA 1. Write up a small program that accepts two integers from the user. Print...
IN JAVA 1. Write up a small program that accepts two integers from the user. Print which of the two values is bigger. If they are the same, print that they are the same. 2. Write a method that accepts three doubles. Calculate and return the average of the three passed double values. 3. Write up a method that accepts a score between 0-10. Print out a message according to the following table. You ay personally decide the boundaries. i.e.,...
please create a C++ program that will ask the user how many times to roll a...
please create a C++ program that will ask the user how many times to roll a pair of dice. The choices are 10, 20 & 50. Allow the user to select 1 choice and error if none of the choices are valid. The program will then the desired amount. The program will keep track of the running total of the sum of the dice (i.e. 5, 2 = 7; 3,6 =7+9 = 16). The program will then produce the total...
For this assignment, design and implement a class to represent a die (singular of "dice"). A...
For this assignment, design and implement a class to represent a die (singular of "dice"). A normal bag of dice for playing Dungeons and Dragons, for example, contains dice with the following numbers of sides: 4, 6, 8, 10, 12, 20, and 100. In this program, the sides (or faces) of the die are numbered, starting with one. The current face value of the die corresponds to the side that is currently facing upward. By default, the face value is...
SITUATION : Assume that you have to write a program to provide solution to problem face...
SITUATION : Assume that you have to write a program to provide solution to problem face by the company of ABC. The company is providing a service of renting a venue and place such as futsal court, badminton court booking and etc. There are several problems which face by the company in which they have to do it manually. One of the problems maybe during booking of venue. Another problem maybe face by the employee is to reserve the place...
PROBLEM #2 Suppose you play a game in which a fair 6 sided die is rolled...
PROBLEM #2 Suppose you play a game in which a fair 6 sided die is rolled once. If the outcome of the roll (the number of dots on the side facing upward) is less than or equal to 4, you are paid as many dollars as the number you have rolled. Otherwise, you lose as many dollars as the number you have rolled. Let X be the profit from the game (or the amount of money won or lost per...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT