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
#include <iostream>
#include <cstdlib>
#include <ctime>
usingnamespace 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':
returntrue;
break;
case'Y':
returntrue;
break;
case'n':
returnfalse;
break;
case'N':
returnfalse;
break;
default:
returntrue;
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; }
elseif (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;
}