Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

DB2 Universal Database V7.1 Application Development Certification Guide

Authors: Steve Sanyal, David Martineau, Kevin Gashyna, Michael Kyprianou

1st Edition

0130913677, 978-0130913678

More Books

Students also viewed these Databases questions

Question

LO2.5 Describe the mechanics of the circular flow model.

Answered: 1 week ago

Question

LO2.6 Explain how the market system deals with risk.

Answered: 1 week ago