Thirteen Stones

Discussion in 'C++' started by coinjo, Oct 20, 2005.

  1. coinjo

    coinjo Guest

    In "Thirteen Stones" game, two players alternately take 1, 2, or 3
    stones from a pile of 13 stones until no stones are left. The last
    player to pick up a stone is the winner.

    I need to make a program that simulates the "Thirteen stones" game.
    My program should alternately ask the players to select how many stones
    they wish to remove from the pile. If the selection is valid (1, 2, or
    3 stones), the selected number of stones should be removed from the
    pile. If a player enters an invalid number of stones, the program
    should display an error message and ask the player to select again.
    Continue play until no stones are left, and display a message
    indicating the winner.

    Input: Number of stones (1, 2, or 3) chosen on each turn
    Output: A message declaring the winner.

    Any hints please?
     
    coinjo, Oct 20, 2005
    #1
    1. Advertising

  2. coinjo

    red floyd Guest

    coinjo wrote:
    > In "Thirteen Stones" game, two players alternately take 1, 2, or 3
    > stones from a pile of 13 stones until no stones are left. The last
    > player to pick up a stone is the winner.
    >
    > I need to make a program that simulates the "Thirteen stones" game.
    > My program should alternately ask the players to select how many stones
    > they wish to remove from the pile. If the selection is valid (1, 2, or
    > 3 stones), the selected number of stones should be removed from the
    > pile. If a player enters an invalid number of stones, the program
    > should display an error message and ask the player to select again.
    > Continue play until no stones are left, and display a message
    > indicating the winner.
    >
    > Input: Number of stones (1, 2, or 3) chosen on each turn
    > Output: A message declaring the winner.
    >
    > Any hints please?
    >


    Accept input.
    Process input.
    Generate output.

    In other words, we won't do your homework for you. Make your best
    effort, show us what you've come up with, and then we'll help.

    See FAQ 5.2: http://www.parashift.com/c -faq-lite/how-to-post.html#faq-5.2
     
    red floyd, Oct 20, 2005
    #2
    1. Advertising

  3. coinjo

    Mike Wahler Guest

    "coinjo" <> wrote in message
    news:...
    > In "Thirteen Stones" game, two players alternately take 1, 2, or 3
    > stones from a pile of 13 stones until no stones are left. The last
    > player to pick up a stone is the winner.
    >
    > I need to make a program that simulates the "Thirteen stones" game.
    > My program should alternately ask the players to select how many stones
    > they wish to remove from the pile. If the selection is valid (1, 2, or
    > 3 stones), the selected number of stones should be removed from the
    > pile. If a player enters an invalid number of stones, the program
    > should display an error message and ask the player to select again.
    > Continue play until no stones are left, and display a message
    > indicating the winner.
    >
    > Input: Number of stones (1, 2, or 3) chosen on each turn
    > Output: A message declaring the winner.
    >
    > Any hints please?


    Yes. Show some effort. If you actually try, and
    when you get stuck, post your code with specific
    questions, then we'll help. Nobody is going to
    do it for you.

    -Mike
     
    Mike Wahler, Oct 20, 2005
    #3
  4. coinjo wrote:
    > In "Thirteen Stones" game, two players alternately take 1, 2, or 3
    > stones from a pile of 13 stones until no stones are left. The last
    > player to pick up a stone is the winner.
    >
    > I need to make a program that simulates the "Thirteen stones" game.
    > My program should alternately ask the players to select how many stones
    > they wish to remove from the pile. If the selection is valid (1, 2, or
    > 3 stones), the selected number of stones should be removed from the
    > pile. If a player enters an invalid number of stones, the program
    > should display an error message and ask the player to select again.
    > Continue play until no stones are left, and display a message
    > indicating the winner.
    >
    > Input: Number of stones (1, 2, or 3) chosen on each turn
    > Output: A message declaring the winner.
    >
    > Any hints please?
    >


    If you really can't make some progress on that question by yourself then
    maybe you should consider another direction. Programming assignments
    don't get much easier, its a single simple loop.

    Now of course in attempting to solve this you might get stuck, that's
    expected, but you should be able to at least attempt a solution by yourself.

    john
     
    John Harrison, Oct 20, 2005
    #4
  5. coinjo wrote:
    >
    > In "Thirteen Stones" game, two players alternately take 1, 2, or 3
    > stones from a pile of 13 stones until no stones are left. The last
    > player to pick up a stone is the winner.
    >
    > I need to make a program that simulates the "Thirteen stones" game.
    > My program should alternately ask the players to select how many stones
    > they wish to remove from the pile. If the selection is valid (1, 2, or
    > 3 stones), the selected number of stones should be removed from the
    > pile. If a player enters an invalid number of stones, the program
    > should display an error message and ask the player to select again.
    > Continue play until no stones are left, and display a message
    > indicating the winner.
    >
    > Input: Number of stones (1, 2, or 3) chosen on each turn
    > Output: A message declaring the winner.
    >
    > Any hints please?


    It boils down to having an int variable, maybe you call it 'pile',
    that is counted down, where users tell the program how much it
    has to count down. When 'pile' reaches 0, the user doing the last
    input is the winner.


    --
    Karl Heinz Buchegger
     
    Karl Heinz Buchegger, Oct 20, 2005
    #5
  6. coinjo

    coinjo Guest

    #include<iostream.h>
    void main()
    {
    char selection;
    int stones=13;
    int done1=0;
    while(stones>0 && done1!=1)
    {
    if(stones>0)
    {
    selection=0;
    cout<<"Player 1 Enter Your Selection"<<endl;
    cin>>selection;
    if(selection=='1')
    {
    if(stones>0)
    stones=stones-1;
    else
    {
    cout<<"Invalid Selection. Enter Again"<<endl;
    cin>>selection;
    }
    }
    if(selection=='2')
    {
    if(stones>1)
    stones=stones-2;
    else
    {
    cout<<"Invalid Selection. Enter Again"<<endl;
    cin>>selection;
    }
    }
    if(selection=='3')
    {
    if(stones>2)
    stones=stones-3;
    else
    {
    cout<<"Invalid Selection. Enter Again"<<endl;
    cin>>selection;
    }
    }

    if(stones==0)
    {
    cout<<"Player 1 Wins"<<endl;
    done1=1;
    }
    }

    if(stones>0 && done1!=1)
    {cout<<"Player 2 Enter Your Selection"<<endl;
    cin>>selection;
    if(selection=='1')
    {
    if(stones>0)
    {
    stones=stones-1;
    }
    else
    {
    cout<<"Invalid Selection. Enter Again"<<endl;
    cin>>selection;
    }
    }


    if(selection=='2')
    {
    if(stones>10)
    {
    stones=stones-2;
    }
    else
    {
    cout<<"Invalid Selection. Enter Again"<<endl;
    cin>>selection;
    }
    }
    if(selection=='3')
    {
    if(stones>2)
    {
    stones=stones-3;
    }
    else
    {
    cout<<"Invalid Selection. Enter Again"<<endl;
    cin>>selection;
    }
    }
    if(stones==0)
    {
    cout<<"Player 2 wins"<<endl;
    done1=1;
    }

    }
    }
    }

    This is the best i can come up with. But there are problems in its
    output. When i constantly enter 1. It should stop at player 1 wins but
    it stops at player 2 wins. Now that i have tried the code. Can anyone
    help me?
     
    coinjo, Oct 20, 2005
    #6
  7. coinjo

    mlimber Guest

    coinjo wrote:
    > #include<iostream.h>
    > void main()
    > {
    > char selection;
    > int stones=13;
    > int done1=0;
    > while(stones>0 && done1!=1)
    > {
    > if(stones>0)
    > {
    > selection=0;
    > cout<<"Player 1 Enter Your Selection"<<endl;
    > cin>>selection;
    > if(selection=='1')
    > {
    > if(stones>0)
    > stones=stones-1;
    > else
    > {
    > cout<<"Invalid Selection. Enter Again"<<endl;
    > cin>>selection;
    > }
    > }
    > if(selection=='2')
    > {
    > if(stones>1)
    > stones=stones-2;
    > else
    > {
    > cout<<"Invalid Selection. Enter Again"<<endl;
    > cin>>selection;
    > }
    > }
    > if(selection=='3')
    > {
    > if(stones>2)
    > stones=stones-3;
    > else
    > {
    > cout<<"Invalid Selection. Enter Again"<<endl;
    > cin>>selection;
    > }
    > }
    >
    > if(stones==0)
    > {
    > cout<<"Player 1 Wins"<<endl;
    > done1=1;
    > }
    > }
    >
    > if(stones>0 && done1!=1)
    > {cout<<"Player 2 Enter Your Selection"<<endl;
    > cin>>selection;
    > if(selection=='1')
    > {
    > if(stones>0)
    > {
    > stones=stones-1;
    > }
    > else
    > {
    > cout<<"Invalid Selection. Enter Again"<<endl;
    > cin>>selection;
    > }
    > }
    >
    >
    > if(selection=='2')
    > {
    > if(stones>10)
    > {
    > stones=stones-2;
    > }
    > else
    > {
    > cout<<"Invalid Selection. Enter Again"<<endl;
    > cin>>selection;
    > }
    > }
    > if(selection=='3')
    > {
    > if(stones>2)
    > {
    > stones=stones-3;
    > }
    > else
    > {
    > cout<<"Invalid Selection. Enter Again"<<endl;
    > cin>>selection;
    > }
    > }
    > if(stones==0)
    > {
    > cout<<"Player 2 wins"<<endl;
    > done1=1;
    > }
    >
    > }
    > }
    > }
    >
    > This is the best i can come up with. But there are problems in its
    > output. When i constantly enter 1. It should stop at player 1 wins but
    > it stops at player 2 wins. Now that i have tried the code. Can anyone
    > help me?


    Here's a more readable version of the program:

    #include<iostream> // N.B., iostream.h is deprecated
    using namespace std;

    int main() // N.B., not void main()
    {
    char selection;
    int stones=13;
    int done1=0; // Could be a bool instead of an int
    while(stones>0 && done1!=1)
    {
    if(stones>0) // Redundant. The while condition ensures that
    // this is true.
    {
    selection=0;
    cout<<"Player 1 Enter Your Selection"<<endl;
    cin>>selection;
    if(selection=='1')
    {
    if(stones>0) // Redundant
    stones=stones-1; // stones -= 1; is more
    compact
    else
    { // This else condition will never be reached
    // because stones will always be > 0. If it were
    reached,
    // however, it would ask the user for input but not
    test
    // to see if the input is 1 again. The same thing
    applies
    // to the other else's below, except they can be
    reached!

    cout<<"Invalid Selection. Enter Again"<<endl;
    cin>>selection;
    }
    }

    if(selection=='2') // Should be: else if( selection=='2' )
    {
    if(stones>1)
    stones=stones-2;
    else
    {
    cout<<"Invalid Selection. Enter Again"<<endl;
    cin>>selection;
    }
    }

    if(selection=='3') // Use else if here, too
    {
    if(stones>2)
    stones=stones-3;
    else
    {
    cout<<"Invalid Selection. Enter Again"<<endl;
    cin>>selection;

    }
    }

    if(stones==0)
    {
    cout<<"Player 1 Wins"<<endl;
    done1=1;
    // continue; // Would skip the next part
    }
    }

    if(stones>0 && done1!=1)
    {
    cout<<"Player 2 Enter Your Selection"<<endl;
    cin>>selection;
    if(selection=='1')
    {
    if(stones>0) // Redundant
    {
    stones=stones-1;
    }

    else
    {
    cout<<"Invalid Selection. Enter Again"<<endl;
    cin>>selection;

    }
    }

    if(selection=='2')
    {
    if(stones>10)
    {
    stones=stones-2;
    }

    else
    {
    cout<<"Invalid Selection. Enter Again"<<endl;
    cin>>selection;
    }
    }

    if(selection=='3')
    {
    if(stones>2)
    {
    stones=stones-3;
    }

    else
    {
    cout<<"Invalid Selection. Enter Again"<<endl;
    cin>>selection;
    }
    }

    if(stones==0)
    {
    cout<<"Player 2 wins"<<endl;
    done1=1;
    }
    }
    }
    return 0;
    }


    On a cursory reading, I'd guess that the faulty error checking is your
    problem. If you enter the thirteen 1's without error, it might work
    (though I didn't test it). What you need to do is either learn to use
    the debugger that is undoubtedly included with your development
    environment, or more simply put some extra cout's in the code so you
    can tell what the program is doing at each point.

    Cheers! --M
     
    mlimber, Oct 20, 2005
    #7
  8. coinjo wrote:
    >


    > if(stones>0 && done1!=1)
    > {cout<<"Player 2 Enter Your Selection"<<endl;
    > cin>>selection;
    > if(selection=='1')
    > {
    > if(stones>0)
    > {
    > stones=stones-1;
    > }
    > else
    > {
    > cout<<"Invalid Selection. Enter Again"<<endl;
    > cin>>selection;
    > }
    > }
    >
    > if(selection=='2')
    > {
    > if(stones>10)


    10 ???

    > {
    > stones=stones-2;
    > }

    ....
    >
    > This is the best i can come up with. But there are problems in its
    > output.


    My I suggest you output the number of stones left on the pile
    before you ask each player for his turn?

    > When i constantly enter 1. It should stop at player 1 wins but
    > it stops at player 2 wins. Now that i have tried the code. Can anyone
    > help me?


    If I run your program and always enter 1, then the program ends with
    'Player 1 wins'

    Hint: it is always a good idea, to output a few intermediate results.
    Eg. before you ask each player for his choice, show him the number
    of stones left on the pile.
    Also: After getting an input from the user, it is also a good idea
    to report to the user what the program has read and what it does with that
    input.
    eg.

    if( stones > 0 )
    {
    selection = 0;
    cout << "There are " << stones << " stones left on the pile.\n";
    cout << "Player 1 Enter Your Selection (1-3)" << endl;

    cin >> selection;
    if( selection == '1' )
    {
    if( stones > 0 )
    {
    cout << "Player 1 choosed to take 1 stone.\n";
    stones = stones-1;
    }
    else
    {
    ...

    This not only reduces the confusion for the person sitting infront
    of the computer. It also allows the devloper of the program to monitor
    if things go the way he intended them to go.

    Hint 2:
    A few whitespace characters in the source code can do wonders in readability.
    Indenting the code is not only a luxary, but is also a good tool in fighting
    bugs (although that might have happend during your code posting)

    --
    Karl Heinz Buchegger
     
    Karl Heinz Buchegger, Oct 20, 2005
    #8
  9. coinjo

    Jim Langston Guest

    "coinjo" <> wrote in message
    news:...
    > #include<iostream.h>
    > void main()
    > {
    > char selection;
    > int stones=13;
    > int done1=0;
    > while(stones>0 && done1!=1)
    > {
    > if(stones>0)
    > {
    > selection=0;
    > cout<<"Player 1 Enter Your Selection"<<endl;
    > cin>>selection;


    > if(selection=='1')
    > {
    > if(stones>0)
    > stones=stones-1;
    > else
    > {
    > cout<<"Invalid Selection. Enter Again"<<endl;
    > cin>>selection;
    > }
    > }
    > if(selection=='2')
    > {
    > if(stones>1)
    > stones=stones-2;
    > else
    > {
    > cout<<"Invalid Selection. Enter Again"<<endl;
    > cin>>selection;
    > }
    > }
    > if(selection=='3')
    > {
    > if(stones>2)
    > stones=stones-3;
    > else
    > {
    > cout<<"Invalid Selection. Enter Again"<<endl;
    > cin>>selection;
    > }
    > }


    Why are you making selection a character instead of an int? Would make it a
    lot easier for you.

    int selection;
    ....
    cin >> selection;

    Now you can get rid of your 3 if statments and do a little math.

    if ( stones >= selection )
    stones -= selection;
    else
    cout << "Invalid Selection" << std::endl;

    You'll need to change your logic there, beucase your
    {
    cout<<"Invalid Selection. Enter Again"<<endl;
    cin>>selection;
    }

    isn't enough. You're having the user reinput the selection, but you've
    already passed up where you do anything with it. Perhaps you might want to
    look at a while block...

    while ( selection = 0 && stones > 0 )
    {
    // do input here and checking and subtraction, etc...
    // if they selected an invalid amount set selection to 0
    // so they have to put it in again
    }

    > if(stones==0)
    > {
    > cout<<"Player 1 Wins"<<endl;
    > done1=1;
    > }
    > }
    >
    > if(stones>0 && done1!=1)
    > {cout<<"Player 2 Enter Your Selection"<<endl;
    > cin>>selection;
    > if(selection=='1')
    > {
    > if(stones>0)
    > {
    > stones=stones-1;
    > }
    > else
    > {
    > cout<<"Invalid Selection. Enter Again"<<endl;
    > cin>>selection;
    > }
    > }
    >
    >
    > if(selection=='2')
    > {
    > if(stones>10)
    > {
    > stones=stones-2;
    > }
    > else
    > {
    > cout<<"Invalid Selection. Enter Again"<<endl;
    > cin>>selection;
    > }
    > }
    > if(selection=='3')
    > {
    > if(stones>2)
    > {
    > stones=stones-3;
    > }
    > else
    > {
    > cout<<"Invalid Selection. Enter Again"<<endl;
    > cin>>selection;
    > }
    > }
    > if(stones==0)
    > {
    > cout<<"Player 2 wins"<<endl;
    > done1=1;
    > }
    >
    > }
    > }
    > }
    >
    > This is the best i can come up with. But there are problems in its
    > output. When i constantly enter 1. It should stop at player 1 wins but
    > it stops at player 2 wins. Now that i have tried the code. Can anyone
    > help me?


    You are duplicating code for the players. You do input for 1, then the
    other. You don't need to. The exact same logic applies in both cases. The
    only thing that changes is the player number.

    int PlayerNumber = 1;
    while(stones>0 && done1!=1)
    {
    // blah blah
    // input, see if won, etc.. here. at end:

    if ( PlayerNumber == 1 }
    PlayerNumber = 2;
    else
    PlayerNumber = 1;

    // If you want you can use trinary for that instead:
    // PlayerNumber = ( PlayerNumber == 1 ? 2 : 1 );
    }
     
    Jim Langston, Oct 20, 2005
    #9
  10. coinjo

    coinjo Guest

    Please suggest changes in the program posted by mlimber and also please
    post the full code again as it is very hard to understand your
    suggestions.
     
    coinjo, Oct 20, 2005
    #10
  11. coinjo

    mlimber Guest

    Re: [OT] Thirteen Stones

    coinjo wrote:
    > Please suggest changes in the program posted by mlimber and also please
    > post the full code again as it is very hard to understand your
    > suggestions.


    We're not going to do your homework for you. Read the post again; I
    think it is sufficiently clear. If you disagree, ask specific questions
    about it. More importantly, note that this discussion is not concerned
    with the C++ language proper and is thus off topic (as I've noted in
    the changed subject line). Please ask in one of the groups I mentioned
    in my previous post.

    Cheers! --M

    PS, You should quote the post you're referring to and put your comments
    *below* it. Not everyone is using Google groups to read these messages,
    and quoting makes it easier for them to follow the discussion. (To
    quote with Google, click on "show options" beside the message you want
    to respond to, and then click "Reply" in the revealed header.)
     
    mlimber, Oct 20, 2005
    #11
  12. coinjo

    coinjo Guest

    Can anybody tell me what does stones -= 1 means?
     
    coinjo, Oct 21, 2005
    #12
  13. coinjo

    coinjo Guest

    #include<iostream.h>
    void main()

    {
    char selection;
    int stones=13;
    int done1=0;
    while(stones>0 && done1!=1)
    {
    if(stones>0)
    {
    selection=0;
    cout<<"Player 1 Enter Your Selection"<<endl;
    cin>>selection;
    if(selection=='1')
    {
    if(stones>0)
    stones=stones-1;
    }


    else if(selection=='2')
    {
    if(stones>1)
    stones=stones-2;
    }


    else if(selection=='3')
    {
    if(stones>2)
    stones=stones-3;
    }


    if(stones==0)
    {
    cout<<"Player 1 Wins"<<endl;
    done1=1;

    }
    }


    if(stones>0 && done1!=1)
    {
    cout<<"Player 2 Enter Your Selection"<<endl;
    cin>>selection;
    if(selection=='1')
    {
    stones=stones-1;
    }


    if(selection=='2')
    {
    if(stones>10)
    {
    stones=stones-2;
    }
    }


    if(selection=='3')
    {
    if(stones>2)
    {
    stones=stones-3;
    }
    }


    if(stones==0)
    {
    cout<<"Player 2 wins"<<endl;
    done1=1;
    }
    }
    }
    }

    i have edited the code somewhat and removed the error part of the
    program. But still the program only works when i enter 1's and not for
    two's or three's. Please suggest changes in the above code.
     
    coinjo, Oct 21, 2005
    #13
  14. coinjo

    coinjo Guest

    #include<iostream.h>
    void main()
    {
    int selection=0;
    int stones=13;
    int player=0;

    while(stones>0)

    {

    cout<<"Enter Player"<<endl;

    cin>>player;

    {

    cout<<"Enter Your Selection"<<endl;

    cin>>selection;

    if(stones>=selection)

    {

    stones=stones-selection;

    }

    else

    cout<<"Invalid Selestion"<<endl;

    }

    if(stones==0)

    {

    if(player==1)

    {

    cout<<"Player 1 Wins!"<<endl;

    }

    else

    cout<<"Player 2 Wins!"<<endl;

    }

    }
    }


    Thanks to all of you for your generous help. I was finally able to make
    the program work with the above syntax. Please Check it and tell me if
    you find any errors in it.
     
    coinjo, Oct 21, 2005
    #14
  15. coinjo

    Jim Langston Guest

    "coinjo" <> wrote in message
    news:...
    > #include<iostream.h>
    > void main()
    > {
    > int selection=0;
    > int stones=13;
    > int player=0;
    >
    > while(stones>0)
    >
    > {
    >
    > cout<<"Enter Player"<<endl;
    >
    > cin>>player;
    >
    > {
    >
    > cout<<"Enter Your Selection"<<endl;
    >
    > cin>>selection;
    >
    > if(stones>=selection)
    >
    > {
    >
    > stones=stones-selection;
    >
    > }
    >
    > else
    >
    > cout<<"Invalid Selestion"<<endl;
    >
    > }
    >
    > if(stones==0)
    >
    > {
    >
    > if(player==1)
    >
    > {
    >
    > cout<<"Player 1 Wins!"<<endl;
    >
    > }
    >
    > else
    >
    > cout<<"Player 2 Wins!"<<endl;
    >
    > }
    >
    > }
    > }
    >
    >
    > Thanks to all of you for your generous help. I was finally able to make
    > the program work with the above syntax. Please Check it and tell me if
    > you find any errors in it.


    If you provide here a complete working program that does what you want, I'll
    show you how I would do it.

    You should probably be posting in:
    alt.comp.lang.learn.c-c++

    as there is a lot more tolerance there for beginner questions on language
    syntax.
     
    Jim Langston, Oct 21, 2005
    #15
  16. coinjo

    Jim Langston Guest

    "coinjo" <> wrote in message
    news:...
    > Can anybody tell me what does stones -= 1 means?
    >


    stones = stones - 1;
    stones -= 1;

    Those two lines do the exact same thing. As would:

    stones = stones + x;
    stones += x;

    += and -= are just a shortcut way of doing it and is quite common in use.
     
    Jim Langston, Oct 21, 2005
    #16
  17. coinjo

    Mike Wahler Guest

    "coinjo" <> wrote in message
    news:...
    > Can anybody tell me what does stones -= 1 means?


    It's the same as:

    stones = stones - 1;

    Similar operators are:

    x += y /* x = x + y */
    x *= y /* x = x * y */
    x /= y /* x = x / y */


    Also equivalent to

    stones -= 1

    is

    --stones

    -Mike
     
    Mike Wahler, Oct 21, 2005
    #17
  18. coinjo

    Mike Wahler Guest

    "coinjo" <> wrote in message
    news:...
    > #include<iostream.h>


    #include <iostream> /* declares 'cin' and 'cout' */
    #include <ostream> /* declares 'endl' */

    using namespace std; /* all library names (except macros)
    are defined in namespace 'std' */

    > void main()


    int main() /* main() is *required* to have
    return type 'int' */

    > {
    > int selection=0;
    > int stones=13;
    > int player=0;
    >
    > while(stones>0)
    >
    > {
    >
    > cout<<"Enter Player"<<endl;
    >
    > cin>>player;


    What happens if I type "abc" at this prompt?

    >
    > {
    >
    > cout<<"Enter Your Selection"<<endl;
    >
    > cin>>selection;


    What happens if I type "abc" at this prompt?

    >
    > if(stones>=selection)
    >
    > {
    >
    > stones=stones-selection;
    >
    > }
    >
    > else
    >
    > cout<<"Invalid Selestion"<<endl;
    >
    > }
    >
    > if(stones==0)
    >
    > {
    >
    > if(player==1)
    >
    > {
    >
    > cout<<"Player 1 Wins!"<<endl;
    >
    > }
    >
    > else
    >
    > cout<<"Player 2 Wins!"<<endl;
    >
    > }
    >
    > }


    return 0; /* optional, but imo 'good practice' */

    > }


    Please indent your code, it's hard to read otherwise.

    >
    >
    > Thanks to all of you for your generous help. I was finally able to make
    > the program work with the above syntax. Please Check it and tell me if
    > you find any errors in it.


    See above.

    -Mike
     
    Mike Wahler, Oct 21, 2005
    #18
  19. coinjo

    mlimber Guest

    Mike Wahler wrote:
    >
    > #include <iostream> /* declares 'cin' and 'cout' */
    > #include <ostream> /* declares 'endl' */

    [snip]

    There's no need to include ostream if iostream is already included.

    Cheers! --M
     
    mlimber, Oct 21, 2005
    #19
  20. coinjo

    mlimber Guest

    Mike Wahler wrote:
    > "coinjo" <> wrote in message
    > > cout<<"Enter Player"<<endl;
    > >
    > > cin>>player;

    >
    > What happens if I type "abc" at this prompt?

    [snip]

    One more comment for the OP: what happens if you enter any other number
    (e.g., -10, 42000, 8675309)? You shouldn't be letting the user control
    this variable since the rules of the game mandate that turns alternate
    between two and only two players. Instead, you should put the logic for
    the players in a loop:

    while( stones > 0 )
    {
    for( int player = 1; player <= 2; player++ )
    {
    // Put stone selection logic here
    }
    }

    Cheers! --M
     
    mlimber, Oct 21, 2005
    #20
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. meital

    sorting an array of three kinds of stones

    meital, Oct 28, 2004, in forum: C Programming
    Replies:
    17
    Views:
    592
    Pedro Graca
    Oct 29, 2004
Loading...

Share This Page