C++ help

Discussion in 'OT Technology' started by MZ2215, Feb 18, 2003.

  1. MZ2215

    MZ2215 Yep

    Joined:
    Jul 21, 2001
    Messages:
    13,234
    Likes Received:
    3
    Location:
    Michigan
    I had to write a program to play "The Nim game", pretty simple concept, 2 players, three rows of sticks containg 7/5/3 sticks respectively, player picks row then number of sticks, goes between players until all are gone, last one to take a stick loses.

    I'm fairly new to C++, I have most of it (i think) but it won't compile and keeps telling me i have errors and i don't know how to fix them
    here is what i have if someone would look at it for me:

    PHP:
    //CS111
    //Let's Play Nim!

    #include <iostream>
    #include <iomanip>

    using namespace std;

    void Instructions();
    void playBoard(intintintint);
    void disBoard(intint&, int&, int&); 

    int main()
    {
    int player=1row1=7row2=5row3=3;
    instructions();
    do
    {
    disBoard(playerrow1row2row3);
    playBoard(playerrow1row2row3);
    player*=-1;
    }
    while (
    row1>|| row2>|| row3>0);
    if (
    player==1)
    cout << "Player B selected the last stick and loses\n";
    else
    cout << "Player A selected the last stick and loses\n";

    void instructions()
    {
    cout << "Welcome to the game of Nim. This is a two person game\n";
    cout << "with players A and B. The game starts with three rows of\n";
    cout << "sticks containing 7, 5 and 3 sticks respectively.\n";
    cout << "When it's your move, you must select a row containing one\n";
    cout << "or more sticks, and then select at least one stick from\n";
    cout << "only that row. You may select all if you wish. The player\n";
    cout << "taking the last stick loses.\n";
    }
    void disBoard (int playerint row1int row2int row3);
    int count=1;
    if (
    player==1)
    cout << "It is Player A's turn\n";
    else
    cout << "It is Player B's turn\n";

    cout << "The board looks like this:\n";
    cout << "Row 1: ";
    while (
    count<=row1)
    {
    cout << "| ";
    count ++;
    }
    count=1;
    cout << "Row 2: ";
    while (
    count<=row2)
    {
    cout << "| ";
    count ++;
    }
    count=1;
    cout << "Row 3: ";
    while (
    count<=row3)
    {
    cout <<"| ";
    count++;
    }
    Void playBoard(int playerintrow1int&row2introw3)
    {
    int rowchoicenumsticks;
    bool nosticks=false;
    do
    {
    nosticks=false;
    do
    {
    if(
    player==1)
    cout << "Player A, ";
    else
    cout << "Player B, ";
    cout << "Pick a row\n";
    cin << rowchoice;
    if(
    rowchoice<||rowchoice>3);
    switch(
    rowchoice)
    {
    case 
    1:
    if(
    row1==0)
    {
    cout << "No sticks are left in Row 1\n";
    nosticks=true;
    break;
    }
    do
    {
    cout << "Draw how many sticks from Row 1?";
    cin >> numsticks;
    if(
    numsticks>row1)
    cout << "Only " << row1 << " sticks left in row 1\n";
    else if(
    numsticks<1)
    cout << "Must draw atleast one stick.\n";
    }
    while(
    numsticks>row1 || numsticks<1);
    row1-=numsticks;
    break;
    case 
    2:
    if(
    row2==0)
    {
    cout << "No sticks left in row 2\n";
    nosticks=true;
    break;
    }
    do
    {
    cout << "Draw how many sticks from row 2?";
    cin >> numsticks;
    if(
    numsticks>row2)
    cout << Only " << row2 <<" sticks in Row 2?\n";
    else if(numsticks<1)
    cout << "
    Must draw atleast one stick\n";
    }
    while(numsticks>row2 || numsticks<1);
    row2-=numsticks;
    break;
    case 3:
    if(row3==0)
    {
    cout << "
    No sticks left in row 2\n";
    nosticks=true;
    break;
    }
    do
    {
    cout << "
    Draw how many sticks from row 3?";
    cin >> numsticks;
    if(numsticks>row2)
    cout << Only " 
    << row3 <<" sticks in Row 3?\n";
    else if(
    numsticks<1)
    cout << "Must draw atleast one stick\n";
    }
    while(
    numsticks>row3 || numsticks<1);
    row2-=numsticks;
    break; 
    }
    }
    while(
    nosticks);
    }
     
  2. FallNAngel

    FallNAngel ...destroyer of threads...

    Joined:
    Jan 15, 2002
    Messages:
    939
    Likes Received:
    0
    Location:
    Right Here (near Chicago)
    pls use
    Code:
     tags to keep the tab formatting.
     
  3. Kent

    Kent Guest

    Can you post the errors?
     
  4. Chimpa Codigo

    Chimpa Codigo Bаnned bу Ѕuреr Modulators

    Joined:
    Jan 27, 2001
    Messages:
    68,463
    Likes Received:
    21
    Location:
    Salinas, CA
    need the errors, but i'll hint on one, everything that you make is case sensitive
     

Share This Page