-
about recursion...
Code:
void PlayerRemove(int &totalstones)
/* remove a stone between 1-3 and check to make sure value of total is not 0 */
{
int playerstones;
cin>>playerstones;
if ((playerstones>3)||(playerstones<1))
{
cout<<"Value must be between 1 and 3"<<endl;
cout<<"How many would you like? ";
PlayerRemove(totalstones);
}
if ((totalstones-playerstones)<=0)
{
cout<<"Value must be between 1 and "<<totalstones<<endl;
cout<<"How many would you like? ";
PlayerRemove(totalstones);
}
totalstones=totalstones-playerstones;//here is the problem i only want it to do the subtraction if the number is between 1-3
}
how does recursion work? does it finish the whole function or start a new one where it left off? and how should i change this so it wont subtract from total if the number is not between 1-3
-
Eh, I don't think what you're trying to do should be done with recursion.
Recursion calls the same function with a different value (HOPEFULLY THERE'S AN EXIT CONDITION SOMEWHERE), and will finish up the rest of the function after the recursive call after the 'other' functions have executed.