Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

can you explain this program in detail. It is the game of NIM where each player picks up 1-4 sticks from a pile of 22.

can you explain this program in detail. It is the game of NIM where each player picks up 1-4 sticks from a pile of 22. I just want to know hpw it works in detial. Thank you
in c++ image text in transcribed
image text in transcribed
//NIM game between two players with 22 sticks #include
#include using namespace std;
int main ()
{
// declaring variables
const int total = 22; bool winner;
string play_again = "y";
int n, mtotal;
while(play_again == "y") {
winner = false;
mtotal = total;
do
{
//Turn for the player 1 to choose the stick (s)
if (mtotal > 0)
{
cout
cout
cin >> n;
if (n >= 1 && n
cout
mtotal -= n;
}
else
{
cout
} if (mtotal
{
winner = true;
cout
}
//turn for the player 1 to choose the stick(s)
if (mtotal > 0)
{
cout
cout
cin >> n;
if (n >= 1 && n
{
cout
mtotal -= n;
}
else
{
cout
}
if (mtotal
{
winner = true;
cout
}
}
}while(!winner);
//Play again if you love this game
cout
cin >> play_again;
}
return 0;
7:46 LTET Rame between the players with include din wardee oli tuta play Wales si total: urn for the player 1 to choose the It metal 1- pics LE out 1 ale Toen for de player to choose the al cut cin LE wekis" Et I. ay in your out you want to play wala ein >> play De 1 //NIM game between two players with 22 sticks #include #include using namespace std; int main() { 1/declaring variables const int total - 22; bool winner string play again - "y": int n, mtotal; while(play again y) winner = false; mtotal - total; do 1/Turn for the player 1 to choose the stick(s) 1 (mtotal > 0) { cout > it in 166 C4) { cout turn for the player 1 to choose the stick(s) 11 (total > 0) cout > if (n >= 1 L cin >> play again; } return 0; >

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

Larry Ellison Database Genius Of Oracle

Authors: Craig Peters

1st Edition

0766019748, 978-0766019744

More Books

Students also viewed these Databases questions