2 Replies - 8646 Views - Last Post: 13 November 2007 - 05:28 PM Rate Topic: -----

#1 dust67  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 2
  • Joined: 13-November 07

C++ code for NIM

Post icon  Posted 13 November 2007 - 04:10 PM

[font=Lucida Console][size=1]

I am trying to write a C++ code for the game of NIM. I must have the user input the turn size and the pile size. I must write the code using while loops and if statements. I have the title, the players entering names, and the loop for the turn size, and the user inputting the pile size. I must validate the loops and figure out the rest of the code. Can anyone help?

Dust67
Is This A Good Question/Topic? 0
  • +

Replies To: C++ code for NIM

#2 William_Wilson  Icon User is offline

  • lost in compilation
  • member icon

Reputation: 205
  • View blog
  • Posts: 4,807
  • Joined: 23-December 05

Re: C++ code for NIM

Posted 13 November 2007 - 04:23 PM

we are more than happy to help. Could you please post what you have done and explain more specifically what troubles you are having? We will not do your homework for you, but we will help explain concept and troubleshoot errors in logic or compilation for sure :)
Was This Post Helpful? 0
  • +
  • -

#3 dust67  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 2
  • Joined: 13-November 07

Re: C++ code for NIM

Posted 13 November 2007 - 05:28 PM

View PostWilliam_Wilson, on 13 Nov, 2007 - 04:23 PM, said:

we are more than happy to help. Could you please post what you have done and explain more specifically what troubles you are having? We will not do your homework for you, but we will help explain concept and troubleshoot errors in logic or compilation for sure :)


Thanks so much. This is what I have so far. I don't understand which loop I need to increment. I have never played the game of NIM before. I also have to test to see who wins. Do I need to create other variables and another loop to do that?
#include<iostream>
#include<cstring>
using namespace std;


int main()

{
	int pileSize = 0;				  //size if pile of chips at start of game
	int turnSize = 0;				  //maximum number of chips a player can take each turn
	int chipsTaken1 = 0;			   //chips taken by player 1
	int chipsTaken2 = 0;			   //chips taken by player 2
	const int size = 30;			   //size limit for name string
	char name1[size], name2[size];	 //names of players
	char ans;						  //user input for another game

	cout<<"\t\tWelcome to the game of NIM\n";

	cout<<"Please enter the name of player 1.";
	cin>>name1;

	cout<<"Please enter the name of player 2.";
	cin>>name2;

	cout<<"Please enter how many chips you may take during a turn.";
	cin>>turnSize;

	while(turnSize < 1)
	{
		cout<<"Your turn size must be greater than 1.  Please choose again.\n";
		cin>>turnSize;
	}

	cout<<"Please enter the number of chips in the pile at the start of the game.";
	cin>>pileSize;

	while(pileSize > turnSize)
	{
		cout<<"How many chips would you like to take? ";
		cin>>chipsTaken1;
	}

	if(1 <= chipsTaken1 || chipsTaken1 <= 3)
	{
		pileSize = pileSize - chipsTaken1;
	}




		
	return(0);


}

Was This Post Helpful? 1

Page 1 of 1