the game is: there are two players. one player selects how many chips there are in the pile to start with. then he takes some chips, then player two takes some, then back to player 1, and so on until there is only 1 chip left. caveats are that each player can only take up to half of the available amount, and must take more than one. this is my code so far. i know it's sloppy and needs some neatening up and better wording, but i want to get it functioning properly first before i worry about all that. so i need the program to keep executing until there's just one chip, and whenever someone enters and invalid amount (say more than half of the available amount) they are repeatedly asked to input a different number. right now the two main problems i'm having are that it's not repeating itself, it's stopping (i'll point out where), and the problem with the math. ok here's the code and i'll have some comments at the bottom.

now with the math issue... i need the number of chips to be continually decreasing as the players take chips out of the pile. but i can't think of a way to do that. right now, every time either player inputs a value for a, the previous a is then overwritten, and the number of chips available basically resets.Code:#include <iostream> #include <iomanip> #include <string> #include <math.h> using namespace std; int main() { int a, b, c, d, pile_size, turn_size, num_chips, initial_number_of_chips, chips_left; string player_1, player_2; cout << "\nRules: The game starts with a pile of chips. Eaech player may only take at\n"; cout << "most half of the chips. The player that gets the last chip wins. Good luck." << "\nPlayer 1 please enter your first name:"; cin >> player_1; cout << "\nPlayer 2 please enter your first name:"; cin >> player_2; cout <<"\nThe current player is" << player_1; cout << "\n How many chips you would like to start with, " << player_1; cin >> initial_number_of_chips; while (a>1) { cout<< "\nPlayer 1 it is your turn, how many chips would you like to take?"; cin>>a; while (a>(initial_number_of_chips/2) || a<1) { cout<<"\nplease enter a different value"; cin>>a; } while (a <=initial_number_of_chips/2 || a>=1) { cout<<"\n There are" <<initial_number_of_chips-a<< "left"; cout<<"\n"<<player_2<<"it is your turn, please select how many chips you would like"; cin>>a; } while (a >(initial_number_of_chips-a)/2 || a<1) { cout<<"\nplease enter a different value"; cin>>a; } while (a <=(initial_number_of_chips-a)/2 || a>1) { cout<<"\nThere are"<<initial_number_of_chips-a<<"left";// at this point, it keeps repeating the loop for player 2 and not jumping back up to player 1} } return 0; }

example: start with 200 chips.

player 1 takes 50

there are 150 left

player 2 takes 70

now it will go back to the initial 200 and subtract 70, giving me 130 left.

i know this is a lot, but can anyone give me some tips? i'm a beginner at this and this is my first time trying a program with multiple loops in it, and it's not coming easy. also don't worry about all the int variables, i've been messing around with different things and just haven't deleted the ones i'm not using yet.