Question: I am writting a program in C for the game of yahtzee. Right now my program asks if the player wants to reroll their dice,

I am writting a program in C for the game of yahtzee. Right now my program asks if the player wants to reroll their dice, but I need the program to ask which dice to reroll and then only reroll those dice, not all 5 dice. How would this code look?? So far I have 2 functions which I call in my play_game function. The output asks for "which dice to reroll" but doesnt actually reroll and display new values, just the old ones. Help!

int reroll(int count)

{

int reroll_index = 0;

int num_reroll = 0;

int dice[5] = { 0 };

printf("How many dice would you like to reroll? ");

scanf("%d", &num_reroll);

for (count = 0; count < num_reroll; ++count)

{

printf("Which die would you like to reroll (1 - 5): ");

scanf("%d", &reroll_index);

dice[reroll_index - 1] = rand() % 6 + 1; // replace the die with another

}

system("pause");

system("cls");

}

void print_dice(int *dice, int size)

{

int index = 0;

for (index = 0; index < size; ++index)

{

printf("%d: %d ", index + 1, dice[index]);

}

}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!