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%.
#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:
Get Answers For Free
Most questions answered within 1 hours.