[Solved] C Program Ll Write Program Uses Recursive Function Program Plays Simple Token Taking Game Q37217707
C++
For this program you’ll write a program that uses a recursivefunction.
This program plays a simple token-taking game. The rules aresimple:
- You start the game with exactly 13 tokens.
- On each turn, you may do one of two things:
- You may ask for exactly 25 more tokens; or,
- IF the number of tokens you have is an even number, you maygive back exactly half of the tokens you have.
- The object of the game is to reach exactly K tokenswithin N turns, where K and N arespecified at the start of each game.
Think about this problem recursively; if the goal is to reach,say, 34 tokens within 10 turns, and I begin with 13 tokens andchoose to take 25 more, then I have 38 tokens and 9 turns left.Your program must be recursive to get full credit.
Your program should ask the user for the goal number of tokens,and the number of turns allowed. It should then search and eitherreport to the user that the total cannot be reached within thedesired number of turns, or the exact sequence of moves for doingso, in order from the start state .There may be more than 1 pathfrom the starting state to the winning state; you do not need tofind them all, count them all, or find the shortest one, only finda valid path within the specified number of turns if oneexists.
Output Sample:
Enter the number of tokens you want to reach:
34
What is the number of turns:
10
Searching for solution within 10 turn(s)…
Adding 25, you get 38 tokens.
Reducing by half, you get 19 tokens.
Adding 25, you get 44 tokens.
Reducing by half, you get 22 tokens.
Reducing by half, you get 11 tokens.
Adding 25, you get 36 tokens.
Reducing by half, you get 18 tokens.
Reducing by half, you get 9 tokens.
Adding 25, you get 34 tokens.
Solution found with 1 turn(s) remaining.
Would you like to play again? [Y/N]
y
Enter the number of tokens you want to reach:
79
What is the number of turns:
10
Searching for solution within 10 turn(s)…
Adding 25, you get 38 tokens.
Reducing by half, you get 19 tokens.
Adding 25, you get 44 tokens.
Reducing by half, you get 22 tokens.
Reducing by half, you get 11 tokens.
Adding 25, you get 36 tokens.
Reducing by half, you get 18 tokens.
Reducing by half, you get 9 tokens.
Adding 25, you get 34 tokens.
Reducing by half, you get 17 tokens.
Sorry, solution wasn’t found within allotted turns.
Would you like to play again? [Y/N]
n
Thanks for playing!
Expert Answer
Answer to C++ For this program you’ll write a program that uses a recursive function. This program plays a simple token-taking gam… . . .
OR

