while loop with int variables
i'm just going to post the while loop portion of the code, because the rest of it above that is working fine. so before this loop, a player selected a number of chips to start with, then took out how many he wanted, then we enter the loop. so a is the number that he took, and intial_number_of_chips is how many chips there were to start. both are ints. i'll post the code and describe my problem at the end
Code:
b=0
c=0
while (num_chips>1)
{
num_chips=initial_number_of_chips-a-b-c;
cout<<"\n"<<player_2<<"it is your turn, please select how many chips you would like";
cin>>b;
while (b >(num_chips)/2 || b<1)
{
cout<<"\nplease enter a different value";
cin>>b;
}
if (b <=(num_chips)/2 || b>1)
{
num_chips=initial_number_of_chips-a-b-c;
cout<<"\nThere are"<<num_chips<<"left";
cout<<"\n"<<player_1<<"it is your turn. please select how many chips you would like";
cin>>b;
}
while (b>(num_chips)/2 || b<1)
{
cout<<"\nPlease enter a different value";
cin>>b;
}
if (b<=(num_chips)/2|| b>=1)
{
num_chips=initial_number_of_chips-a-b-c;
cout<< "there are"<<num_chips<<"chips left";
}
}
return 0;
}
i set b=0 and c=0 outside the loop because when i didn't, odd and unpleasant things happened. anyways, the game is that players select chips, they can't take more than half the available amount, and can't take less than 1. the loop is working fine down to the bottom of it, but when it goes back to the top and the user inputs a new value for b, it's returning a value of initial_number_of_chips-a-b (but the new b, and it's throwing out the old one). i need to it to keep the old b, because it needs to keep subtracting from the available chips again and again until it's down to 1. but it's just resetting each time. any ideas on how to alter this code? i'm not worried about the neatness of it right now, just want to get the loop working first.