Write a program that starts with three "piles" of 3 counters each. Let the player choose piles and remove counters until all the piles are empty.
You do not need to check for errors like a wrong pile name, or if someone tries to take more counters from the pile than the pile has.
Here is an example game, with starting piles of 3 counters.
A: 3 B: 3 C: 3 Choose a pile: A How many to remove from pile A: 2 A: 1 B: 3 C: 3 Choose a pile: C How many to remove from pile C: 3 A: 1 B: 3 C: 0 Choose a pile: B How many to remove from pile B: 1 A: 1 B: 2 C: 0 Choose a pile: A How many to remove from pile A: 1 A: 0 B: 2 C: 0 Choose a pile: B How many to remove from pile B: 1 A: 0 B: 1 C: 0 Choose a pile: C How many to remove from pile C: 2 A: 0 B: 1 C: -2 Choose a pile: B How many to remove from pile B: 1 A: 0 B: 0 C: -2 All piles are empty. Good job!
©2013–2016 Graham Mitchell
This assignment is licensed under a
Creative Commons Attribution-NonCommercial-ShareAlike 3.0 United States License.