33.3k views
2 votes
Programming Assignment: An Array of Treasure B Assignment Develop the code to solve the problem statement below. Follow these style guidelines as you develop the code, use commenting to describe your code, practice debugging if you run into errors, and submit your final source code. Problem Statement: You are designing a game that has five treasure chests located on a map and only the fifth chest contains the token required to level up. You want to track which chest the player has found and opened. Create a Boolean array that stores five elements, and initialize them all to false. Next, ask the user to input which chest he or she just found (1-5). Using the input, use pointers to update the array to true for the chest just found. Then print out to the player if he or she levels up based on the Boolean of the fifth chest. To complete this assignment, review the Programming Guidelines and Rubric document.

User Nodarii
by
7.4k points

1 Answer

5 votes

Final answer:

To track the chests the player has found and opened, use a Boolean array initialized with false values. Update the array element that corresponds to the chest just found using a pointer. Check if the fifth element in the array is true to determine if the player has leveled up.

Step-by-step explanation:

To track the chests that the player has found and opened, an array with five Boolean elements can be used. The array should be initialized with all elements set to false to represent that no chests have been found yet. The user should be prompted to input the number of the chest they just found. Using a pointer, the corresponding element in the array can be updated to true, indicating that the chest has been found. Finally, the program should check if the fifth element in the array is true, indicating that the player has found the token required to level up.

User Benedict Lewis
by
7.5k points