Question: In C++. We want to write a program for playing the game of NIM. Our version of the game starts with up to 20 pegs

In C++.

We want to write a program for playing the game of NIM. Our version of the game starts with up

to 20 pegs and up to 10 discs in each peg. Two players take turns removing discs from the

pegs. On a player's turn, she chooses a peg and removes one or more discs from that peg.

She can remove all discs from the peg. The player who takes the last disc from the pegs (so

that all pegs are empty) loses. This version of the game is called misere.

1- a)Write a procedure (this is a function that does not return a value and so is declared

with a return type of void) that prompt and reads the number of discs in each peg;. Define the

procedure to have three input parameters: the array of pegs, the size of the array,

and the maximum number of discs per peg. This

procedure will traverse the array of pegs and call the following helper procedure for

each peg in the list.

b- Write a helper procedure that will prompt the user for the number of discs to place on

this peg. If the number of discs entered for the peg is not between 1 and the maximum

number of discs allowed then display a warning message and prompt again. Define this

helper procedure to have three input parameters: the array entry for this peg (use pass

by reference), the array index for this peg, and the maximum number of discs per peg.

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!