Help my game

I need help with this part of my code. When the total gets between 2 and 4 it needs to let me choose a number after the computer if the number is 1. If the number is 1, after I ( the player ) chooses the 1 ( forced because its the only thing left ) they are told that they lose. if the number is 0 it should print out that the computer chose the last stick and I win the game. Thanks!


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
   while ( total >=2 && total <= 4 )
            {
                cout << "Enter the number of sticks you wish to pick: "; // Enter the number of sticks
                cin >> sticks;
                while ( sticks <1 || sticks > 3 ) // force user to enter 1, 2, or 3
                {
                    
                    cout << "Your turn. Enter the number of sticks you wish to pick: "; // if user enters a number thats not 1, 2, or 3, force user to enter agina
                    cin >> sticks;
                    cout << " " << endl;
                }
                
                total = total - sticks; //subtract the number of sticks entered
                cout << "You pick " << sticks << " sticks. " << total << " left. " << endl; // print out
                cout << " " << endl; // just a spacer
                
                if ( total == 2 )
                {
                    total --;
                    cout << "Computer picked " << sticks << " sticks " << total << " left." << endl; // print out
                    cout << " " << endl; // another spacer
                }
           
                if ( total == 3 )
                {
                    total = total - 2;
                    cout << "Computer picked " << sticks << " sticks " << total << " left." << endl; // print out
                    cout << " " << endl; // another spacer
                }
              
                if ( total == 4 )
                {
                    total = total - 3;
                    cout << "Computer picked " << sticks << " sticks " << total << " left." << endl; // print out
                    cout << " " << endl; // another spacer
                }
               
            }
            cout << "Your turn. Enter the number of sticks you wish to pick: "; // ask user to enter another
            cin >> sticks; // enter number of sticks
                while ( sticks <1 || sticks > 3 || sticks > total ) // force user to enter 1, 2, or 3 again
                {
                
                cout << "You cannot pick more than left over sticks. Try again: ";// print out
                cin >> sticks; // enter number of sticks
                cout << " " << endl; // another spacer
                    
                }
            
        }
        if ( total == 0 ) // if the ending total is 0
        {
            
            cout << "Congrats! You Win!" << endl; // print out
            cout << " " << endl; // print out spacer
            
        }
        else
        {
            
            cout << "You picked the last stick, you lose!" << endl; //print out
            cout << " " << endl; // print out spacer
            
        }
        
        cout << "Would you like to play again? (Y/N) : " << endl; // ask the user to enter if they want to play again
        cin >> again; // enter y/n
        
     
    }
Topic archived. No new replies allowed.