Title |
Tower of Hanoi |
Author |
james |
Author Email |
james_miguel [at] yahoo.com |
Description |
1. For this program, we will assume that there are 5 disks to be used. 2. When the program starts, draw the starting position of the game. 3. Ask the user to choose the peg where a disk will be removed. The user should input 'A', 'B' or 'C'. Check whether the user made a valid choice and inform the user of any error. Of course, you should also check whether that peg is empty or not (you cannot remove a disk from an empty peg). Your program should also work for lowercase inputs. 4. After the user has correctly chosen a peg where a disk will be removed from, ask the user to which peg will that disk be moved. Remember that you may not place a disk on top of a smaller one. 5. When a disk has been successfully moved in #4, you should draw the new disk positions. For A B C example, if we move a disk from peg A to peg B, using the starting position show in #2, your program should display the updated drawing: 5. Repeat steps #3, #4 and #5. The program should end when all the disks have been correctly placed on peg C. 6. Alternatively, the user may also prematurely end the game by inputting 'Q' in either #3 or #4. 7. Global variables are NOT allowed in your program. 8. Follow the EXACT specifications given for asking input from the user (steps #3 and #4). When testing your program, your instructor will be using input redirection so the input sequence is important.
|
Category |
C » Beginners / Lab Assignments |
Hits |
387121 |
Code |
Select and Copy the Code
|
|
|