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!
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
}