Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Help with this problems in c++ language Thanks Exercise #5: Treasure Hunt A treasure is hidden someplace-the treasures coordinates are (x1,?! The coordinates (x1.yi) are

Help with this problems in c++ language
Thanks image text in transcribed
Exercise #5: Treasure Hunt A treasure is hidden someplace-the treasures coordinates are (x1,?! The coordinates (x1.yi) are determined randomly, using the code that is listed at the end of this exercise. The purpose of the game is for the Explorer to find the Treasure! The explorer is allowed to go North, South, West or East. The Explorer is first positioned at location (15,15). If the explorer goes North, only the y coordinate is increased by 1. Similarly, if the explorer goes South, they coordinate is decreased by . In the same fashion the x coordinate is increased or decreased by 1 depending if the explorer goes East or West, Each time the Explorer moves, the distance between the Explorer and the treasure is computed. The formula for the distance between (x.y) and (x1,y1) sqrt(static_cast ( (x-x1) (x-x1)+(y-yl) (y-y)) When the Explorer's position is the same as the Treasure's position, the Explorer wins the Treasure! Procedures 1. Ask the user to Please enter direction (n, s,e,w), or x to exit: 2. Update the Explorer's coordinates 3. Calculate and display the distance from the Explorer to the Treasure (this information will clue the Explorer to either keep going in the same direction or switch directions). 4. At the end of each loop display the Explorer's coordinates 5. Make sure that you print out how many steps it took to reach the treasure 6. Use the starter code below. #include #include #include #include using namespace std; int main ) // Explorer's coordinates int x=15,y-15; int xi,yl: char direction: float distance; bool treasure false: // Treasure's coordinates // secretly seed the rand function srand (time (0)) x1-rand( ) % 30 + 1; // set X1 to random between 1 and 30 y1-rand( ) % 30 + 1; // set yl to random between land 30

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Genetic Databases

Authors: Martin J. Bishop

1st Edition

ISBN: 0121016250, 978-0121016258

More Books

Students also viewed these Databases questions