Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

In C++ Problem description You will write a program that implements the following version of the game of Nim. Nim is a mathematical strategy game,

In C++

image text in transcribed

image text in transcribed

image text in transcribed

Problem description You will write a program that implements the following version of the game of Nim. Nim is a mathematical strategy game, which dates back to 16th century China. There are many variations on this game, but the version we'll be playing starts with a row of 11 sticks: On their turn a player may remove 1, 2, or 3 sticks from the pile. Players alternate taking turns, and the play removing the last stick wins. Your game should feature two players alternating turns. First, your program should print out a welcome statement and brief instructions. Then, you should display the current game state and prompt player 1 for the number of sticks they should remove: Welcome to Nimi The player removing Players will take turns removing 1, 2, or 3 sticks from the initial 11. the last stick wins! Player 1, it's your turnl The game currently looks like this: How many sticks would you like to remove? (1, 2, or 3) After making sure they entered a valid response, you should remove the appropriate number of sticks. If there are now zero sticks remaining, you should declare that player the winner and end the program. Otherwise, the other player should take a turn. Sample Game: Welcome to Nimi Players will take tums removing 1, 2, or 3 sticks from the initial 11. The player removing the last stick wins! Player 1, it's your turn! The game currently looks like this: How many sticks would you like to remove? (1, 2, or 3) 3 Player 2, it's your turn! The game currently looks like this: How many sticks would you like to remove? (1, 2, or 3) 1 Player 1, it's your turnl The game currently looks like this: How many sticks would you like to remove? (1, 2, or 3) 4 That choice is invalid. How many sticks would you like to remove? (1, 2 or 3) 3 Player 2, it's your turn! The game currently looks like this: How many sticks would you like to remove? (1, 2, or 3) 1 Player 1, it's your turn! The game currently looks like this: How many sticks would you like to remove? (1, 2, or 3) 3 Congratulations Player 1, you win

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

More Books

Students also viewed these Databases questions

Question

Types of Interpersonal Relationships?

Answered: 1 week ago

Question

Self-Disclosure and Interpersonal Relationships?

Answered: 1 week ago