Programming Projects?

I've been programming for a month now, and I seem to have run out of ideas. Please don't suggest project euler (heard it, tried it many times haha). So my question is, what do you guys think i should do? Here is my latest thing that i've made, the game of nim

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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
  #include <iostream>
#include <cstdlib>
#include <ctime>

using namespace std;

int main()
{
    //declares scopes
    int printStones(int stones);
    bool turnCheck(char firstPick);
    int compTurn(int stones);
    int storeCompTurn(int stones);

    //input for number of stones
    int stones;
    cout<<"How many stones are we to start with? ";
    cin>> stones;
    cin.ignore();
    cout<<"\n";

    //if you want to go first or not
    char firstPick;
    cout<<"Would you like to go first or the CPU? y/n: ";
    cin>>firstPick;
    cin.ignore();
    cout<<"\n";

    int stonesToTake;
    int counter = 0;
    while (stones != 0) { //goes while stones are not at 0
        printStones(stones);
        counter++; //increments the loop
        if (turnCheck(firstPick)) { //if user chooses to go first
            bool stoneCheck = false;
            while (!stoneCheck) { //ensures that they input 1 or 2 stones only
                cout<<"How many stones to take away (1 or 2): ";
                cin>>stonesToTake;
                cin.ignore();
                cout<<"\n";

                if (stonesToTake >= 3 || stonesToTake < 1) { //makes it loop until they enter the right number
                    cout<<"You took away the wrong amount! ";
                }
                else {
                    stones = stones - stonesToTake;
                    stoneCheck = true;
                }
            }
            cout<<"You take away: "<<stonesToTake<<" with "<<stones<<" remaining.\n"; //outputs
            printStones(stones);
            cout<<"\n";
            if (stones <= 0) { continue; } //STOPS CP FROM ANSWERING IF ITS ALREADY AT 0
            else {
                stones  = stones - compTurn(stones);
                cout<<"Computer took away: "<< storeCompTurn(stones) <<" with "<<stones<<" remaining.\n";
                cout<<"\n";
            }
        }
        else { //SAME AS ABOVE BUT CP GOES FIRST
            cout<<"\n";
            stones = stones - compTurn(stones);
            cout<<"Computer took away: "<< storeCompTurn(stones) <<" with "<<stones<<" remaining.\n";
            cout<<"\n";

            if (stones <= 0) { continue ;}
            else {

               printStones(stones);
               cout<<"\n";

               bool stoneCheck = false;
            while (!stoneCheck) {
                cout<<"How many stones to take away (1 or 2): ";
                cin>>stonesToTake;
                cin.ignore();
                cout<<"\n";

                if (stonesToTake >= 3 || stonesToTake < 1) {
                    cout<<"You took away the wrong amount! ";
                }
                else {
                    stones = stones - stonesToTake;
                    stoneCheck = true;
                }
            }
            cout<<"You take away: "<<stonesToTake<<" with "<<stones<<" remaining.\n";
            cout<<"\n";
            }
        }
    }
        if (turnCheck(firstPick)) {
             if(counter%2 == 0) { //FIGURE OUT WHO WINS
                cout<<"You win!\n";
        }
            else {
                cout<<"Computer wins!\n";
            }
        }
        else {
            if (counter%2 == 0) {
                cout<<"Computer wins!\n";
            }
            else {
                cout<<"You win!\n";
        }
    }
}

int printStones(int stones) //PRINTS THE STONES
{
    for (int i = 0; i < stones; i++) {
        cout<<"* ";
        if (i%10 == 0) {
            cout<<"\n";
        }
    }
    cout<<"\n";
}

bool turnCheck(char firstPick) //CHECKS IF THE USER IS GOING FIRST
{
    switch(firstPick) {
    case 'y':
        return true;
        break;
    case 'Y':
        return true;
        break;
    case 'n':
        return false;
        break;
    case 'N':
        return false;
        break;
    default:
        return true;
        break;
    }
}

int compTurn(int stones) { //THIS IS THE CP'S TURN
    srand(time(0));

    //ADDED LOGIC AND SOME CP 'BRAINS' FOR DIFFICULTY
    if (stones == 1) { return 1; }
    else if (stones ==2) {return 2; }

    else {
        bool correct = false;
        while (!correct) {
            int randInt = rand()%2+1;
            if (randInt == 2 || randInt == 1) {
                correct == true;
                return randInt;
            }
            else {
                correct = false;
            }
        }
    }
}

int storeCompTurn(int stones) //STORES CP TURN TO OUTPUT LATER
{
    int compTakeAway = compTurn(stones);
    return compTakeAway;
}
Last edited on
Learn a 2D game library (I suggest SFML: http://www.sfml-dev.org ).
Then make clones of popular games: snake, minesweeper, breakout, asteroids, ...
Last edited on
looked at your code. line 133 is a case switch but misses a break.
Oh wow, i looked over the code many times and i didnt find anything, i guess i missed some! and Fransje, thanks, ill look into that :)
Topic archived. No new replies allowed.