Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

i need someone to help me modify this program. the HW question is : Write a prog

ID: 3682667 • Letter: I

Question

i need someone to help me modify this program.

the HW question is :

Write a program that simulates a die, like you did before. This time, however, change your design such that the number of faces becomes a configurable parameter, that is being put in by the user at program start.

here is the program i did before :

#include <stdio.h>

#include <stdlib.h>

#include <string.h>

#include <time.h>

#define The_Sides 6

int main(void)

{

int dice_side[The_Sides]={0};

int i,x,percentage;

printf("Enter how many times you want the dice to be rolled ");

scanf("%d",&x);

for (i = 0; i < x; i++) {

dice_side[rand() % The_Sides]++;

}

printf("Sides No of times Percentage ");

for (i = 0; i < The_Sides; i++){

int number_of_times =dice_side[i];

percentage=number_of_times*100/x;

printf("%d %d %d ", i,number_of_times ,percentage);

}

return 0;

}

*******************************

i need to modify the program to propt the user to enter the number of faces present in the die instead of the fixed value 6 faces.

hi just need someone to modify this part. the program should ask the user for the number of faces and the number of rolls. # of rolls is already done.

Explanation / Answer

#include <stdio.h>

#include <stdlib.h>

#include <string.h>

#include <time.h>

int main(void)

{
//declare the variable
int The_Sides;

//prompt the user
printf("Enter the number of faces present in the dice ");

//read the number of dice faces from user
scanf("%d",&The_Sides);

//declare array
int dice_side[The_Sides];

int i,x,percentage;
//initialize with 0
for(i=0;i<The_Sides;i++)
{
dice_side[i]=0;
}


printf("Enter how many times you want the dice to be rolled ");
//read number of times to roll
scanf("%d",&x);
//roll the dice
for (i = 0; i < x; i++) {

dice_side[rand() % The_Sides]++;

}

printf("Sides No of times Percentage ");

for (i = 0; i < The_Sides; i++){
//calculate number of occurences
int number_of_times =dice_side[i];
//calculate percentage
percentage=number_of_times*100/x;
//display result
printf("%d %d %d ", i,number_of_times ,percentage);

}

return 0;

}