Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

A treasure is hidden someplace the treasures coordinates are (x1, y1)! The coordinates (x1,yl) are determined randomly, using the code that is listed at the

image text in transcribed

A treasure is hidden someplace the treasures coordinates are (x1, y1)! The coordinates (x1,yl) 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, the y coordinate is decreased by 1. In the same fashion the x coordinate is increased or decreased by 1 depending if the explorer goes East or West, respectively. 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) is distance- sqrt (static_cast x-xl) (x-xl) t(y-yl)(y-yl)))i When the Explorer's position is the same as the Treasure's position, the Exploer wins the Treasurel 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 4. 5. 6. will clue the Explorer to either keep going in the same direction or switch directions). At the end of each loop display the Explorer's coordinates. Make sure that you print out how many steps it took to reach the treasure. Use the starter code below #include #include #include #include using namespace std; int main) // Explorer's coordinates int x-15, y 15; int xl,yl; char direction; float distance; bool treasure-false / Treasure' s coordinates // secretly seed the rand function ! srand (time (O)) x]srand ? ? % 30 + 1; // set XI to random between 1 and 30 yl rand ( % 30 + 1; // set yl to random between land 30 //write loop to find the treasure

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

Database Systems On GPUs In Databases

Authors: Johns Paul ,Shengliang Lu ,Bingsheng He

1st Edition

1680838482, 978-1680838480

More Books

Students also viewed these Databases questions