Code:#include <iostream.h> #include <stdlib.h> #include <time.h> //------------------------------------------------------------------------------------------------- void CompRemove(int &totalstones) /* determine the amount of stones the computer will remove */ { int compstones=30; while((compstones>3)||(compstones<1)) { srand(time(NULL)); compstones=((rand() % 3)+1); if ((totalstones-compstones)>=0) { totalstones=totalstones-compstones; cout<<compstones<<endl; } if ((totalstones-compstones)<=0) { CompRemove(totalstones); } } } //------------------------------------------------------------------------------------------------- int GenerateStones() /* generate the amount of stones to start out with */ { int totalstones; srand(time(NULL)); totalstones=((rand() % 15)+15); return (totalstones); } //------------------------------------------------------------------------------------------------- void PlayerRemove(int &totalstones) /* remove a stone between 1-3 and check to make sure value of total is not 0 */ { int playerstones; while(((playerstones>3)||(playerstones<1))||((totalstones-playerstones)<=0)) { cin>>playerstones; if ((playerstones>3)||(playerstones<1)) { cout<<"Value must be between 1 and 3"<<endl; cout<<"How many would you like? "; } if ((totalstones-playerstones)<=0) { cout<<"Value must be between 1 and "<<totalstones<<endl; cout<<"How many would you like? "; } } totalstones=totalstones-playerstones; } //------------------------------------------------------------------------------------------------- void PlayGame() /* start the game and keep track of all the variables during gameplay */ { int totalstones=GenerateStones(); while(totalstones!=0) { cout<<"There are "<<totalstones<<" stones. How many would you like? "; PlayerRemove(totalstones); cout<<"There are "<<totalstones<<" stones. The computer takes "; CompRemove(totalstones); } } //------------------------------------------------------------------------------------------------- int main() { PlayGame(); return (0); }