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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started