need someone to check my work

1. NIM is a game in which two players take turns removing objects from a collection of objects. A player can only take 1, 2, or 3 object(s) per turn.. The game is commonly played with things like toothpicks. The player taking the last object loses.


assignment due tmrw i hope if someone could help me , i am not sure if b,c,d are correct

#include<iostream>
using namespace std;

int main ()
{



int objects,remove;

do

{ cout<<"Welcome to NIM game!\nEnter the initial number of objects to play: "<<endl;
cin>>objects; // here we input the initial number (a)



while(objects<1 &&objects!=-1 ) //the total of objects can't be less than 1

{ cout<<"This is not a valid value.\nEnter a number greater than 1"<<endl;
cin>>objects;}



while(objects>1 && objects!=2) //
{
{cout<<"There is "<<objects<<" object(s).\nEnter the amount(between 1 and 3) that you would like to remove"<<endl;
cin>>remove;}

c. rule: only 1, 2, or 3 object(s) taken per turn (only allow 1 or 2 or 3 objects to be taken not more).


if(remove>=1 && remove<=3)
{ cout<<"You have removed "<<remove<<" objects"<<endl;
objects-=remove;} b. The game should display how many objects remain in the collection after each players’turn.

else

{ cout<<"This is not an acceptable value.\nEnter a value between 1 and 3"<<endl;
cin>>remove;}

{objects-=remove;
}

d. Make sure that there is enough objects at each turn (a player cannot take 3 objects when the number of remaining objects is only 2)

while(objects==2)
{ remove<=2;

cout<<"There is "<<objects<<" objects.\nEnter the amount(between 1 and 3) that you would like to remove"<<endl;
cin>>remove;
objects-=remove;}

e. rule: player taking last object loses (the game should stop when it is over)

if((objects<2 &&objects!=0) ||objects==1)


{cout<<"There is "<<objects<<" objects.\nOne object left...Next player lost\nGame Over\nPress -1 to quit or enter the number of objects to play again "<<endl;
cin>>objects;}
else if(objects==0)
{cout<<"You tooked the last object ... You lost\nGame over\nPress -1 to quit or enter the number of objects to play again\n";
cin>>objects;}}}
while(objects!= -1);
f. Provide a Play again feature
if(objects==-1)
{
cout<<"Thank u for playing\n";}


system("pause");
return 0;
}
Last edited on
Chuck in some code tags and indentation and I'd be happy to take a look.

Looking over plain text is too much for my brain at this hour.
first thank u
second , i am not sure if c and d are correct when trying to execute there is some logic error for exemple there is 9 objects
nb i wish to remove is 3
you have removed 3 objects
there is 3 objects left
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
#include<iostream>
using namespace std;

int main ()
{
    int objects,remove;

    do

    {
        cout<<"Welcome to NIM game!\nEnter the initial number of objects to play: "<<endl;
        cin>>objects; // here we input the initial number (a)



        while(objects<1 &&objects!=-1 ) //the total of objects can't be less than 1

        {
            cout<<"This is not a valid value.\nEnter a number greater than 1"<<endl;
            cin>>objects;
        }



        while(objects>1 && objects!=2) //
        {
            {
                cout<<"There is "<<objects<<" object(s).\nEnter the amount(between 1 and 3) that you would like to remove"<<endl;
                cin>>remove;
            }

//c. rule:
//            only 1, 2, or 3 object(s) taken per turn (only allow 1 or 2 or 3 objects to be taken not more).


            if(remove>=1 && remove<=3)
            {
                cout<<"You have removed "<<remove<<" objects"<<endl;
                objects-=remove;
            }
//            b. The game should display how many objects remain in the collection after each players’turn.

            else

            {
                cout<<"This is not an acceptable value.\nEnter a value between 1 and 3"<<endl;
                cin>>remove;
            }

            {
                objects-=remove;
            }

//            d. Make sure that there is enough objects at each turn (a player cannot take 3 objects when the number of remaining objects is only 2)

            while(objects==2)
            {
                remove<=2;

                cout<<"There is "<<objects<<" objects.\nEnter the amount(between 1 and 3) that you would like to remove"<<endl;
                cin>>remove;
                objects-=remove;
            }

//e. rule:
//            player taking last object loses (the game should stop when it is over)

            if((objects<2 &&objects!=0) ||objects==1)


            {
                cout<<"There is "<<objects<<" objects.\nOne object left...Next player lost\nGame Over\nPress -1 to quit or enter the number of objects to play again "<<endl;
                cin>>objects;
            }
            else if(objects==0)
            {
                cout<<"You tooked the last object ... You lost\nGame over\nPress -1 to quit or enter the number of objects to play again\n";
                cin>>objects;
            }
        }
    }
    while(objects!= -1);
//    f. Provide a Play again feature
    if(objects==-1)
    {
        cout<<"Thank u for playing\n";
    }


    system("pause");
    return 0;
}


Looks nice now, doesn't it?
yes for sure , how can i post it like this ?
can u help me to find the error plz ?
The solution then: Can I have some music? Ta tata ta ta ta Taaaaa!!!
remove the statement at 51 and insert it between 47 and 48.

And By the way, you may want to have a look at statement 58. It has no effect whatsoever
Topic archived. No new replies allowed.