Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Hello! please help me out with the loops in my coding! (Expert Answer in Coding please) !! Looping Multipath Adventure Modify your Multipath Adventure from

Hello! please help me out with the loops in my coding! (Expert Answer in Coding please) !!

Looping Multipath Adventure

Modify your Multipath Adventure from the previous lab to include loops. We suggest that you fulfill the requirements by doing the following:

  • Use a while loop to enable the player to play your game multiple times
  • Create an input function that utilizes a loop to prompt for and validate user input
    • Takes a prompt (string) as the argument
    • Returns the valid input (string)
  • For the requirement to use at least 1 for loop:
    • Consider using for loop(s) to draw box or stars around prompt in your input function (see above)
  • For the requirement to use at least 1 instance of rand():
    • Consider including a randomized process in your game, such as rolling a die, and using rand() to simulate the process
    • Consider including a point where the game randomly selects between multiple possible descriptions. For example, you could have the game randomly decide whether to describe the weather as "sunny" or "rainy".

(If your code already fulfilled these, then you are done!)

If you need to, you can adjust the decision tree as you are programming. Resubmit the final decision tree with the lab submission quiz.

Note that you are allowed to use concepts we have not covered in class if you would like to. This might also help you in preparing for future labs.

The TAs will randomly pick 2 paths through your decision tree to check your work. They will reference your submitted decision tree to choose the paths and make sure that when they run your code it takes them through the path as specified in your decision tree.

To make your game easier to play (and thus make it easier for the TAs to grade) you should provide prompts before each input that make clear what inputs are valid.

A Note On Represent Loops in your Decision Tree

If you choose to represent a loop on your decision tree with an arrow, make sure that you make it clear where the loop starts and where it is going to end. This should only be done if you loop from a "lower" part of your tree to a "higher" part several times. If you have a loop running in the same point of the tree, then you may add a loop arrow if you choose, but you don't have to do so.

Special Requirements:

  • You must adhere to the style guidelines. (up to 10 points)
  • Your code must meet all of the Special Requirements from the previous Multipath Adventure Lab
    • It is fine if you re-organize your code and have different paths or functions than you did in Lab 4, but make sure that you still meet the requirements as listed in Lab 4.
    • If you re-organize your code, make sure to also update your Decision Tree
    • Make sure to review the deductions listed in the previous lab and any feedback you received to avoid losing points here.
  • You must have at least 1 for loop in your code (15 points)
    • The for loop must actually be used as a loop, and it must have real effect in your program (it is theoretically possible to use the for loop syntax without actually using it as a loop or creating any real effect, but if you do this you will lose points)
  • You must have at least 1 while loop in your code (15 points)
    • The note on for loops above applies equally to this deduction regarding while loops
  • You must have at least 1 instance of rand() in your code (5 points)
    • Your use of rand() must have real effect in your program (it is possible to use rand() to generate a random number without actually using the random number, but if you do this you will lose points)
#include  #include  using namespace std; int FlashGoBack(string name, bool hungry); int Game(string name); string RandomName(); int Turn(string name, bool hungry); int HaveMercy(string name); void Clrscr() { system("cls"); } void PrintStar() { for (int i = 0; i < 100; i++) { cout << "*"; } cout << endl; } int main() { string decide2; string name; int cont; int win = 0; cout << "Welcome player!! Enter your name below or enter 0 to get a random name "; PrintStar(); cout << "Enter your name: "; cin >> name; PrintStar(); if (name == "0") name = RandomName(); cout << "Ready to play, " << name << "? "; for (int i = 3; i > -1; i--) { cout << i << " "; sleep(1); } Clrscr(); sleep(1); cout << " (Yesterday you stayed awake until 3 am with your roommates having a good time playing rainbow 6. However, your alarm goes off at 8 am because you have to work at 9 am "; sleep(2); cout << "Do you: "; sleep(1); cout << "(1) Turn off your alarm and go back to sleep (0) Turn off your alarm and get up "; PrintStar(); cout << "What would you choose?(1/0): "; cin >> cont; PrintStar(); if (cont) win = Game(name); if (cont == 0) { cout << "As you are getting ready for work, you remember that you have a project due today! "; PrintStar(); cout << "Do you quickly go to work without having breakfast?(yes/no): "; cin >> decide2; PrintStar(); if (decide2 == "yes") { cout << "You skip breakfast and rush to be on time at work. Some time passes by and you look up at the clock and it's 8:50 am. You panick and grab your stuff. As you do, your roommate yells for help. "; PrintStar(); cout << "Do you help him?(yes/no):"; cin >> decide2; PrintStar(); if (decide2 == "yes") return HaveMercy(name); else cout << "You decide not to help him because you know someone else will help him. You run to work and barely make it on time. You start working on your project and realized that you could get it done by today. (End)"; } else cout << "You decide to take your time and take breakfast because what's the point of cramming when you know you are going to quit your job anyways. (End)"; } return 0; } string RandomName() { string names[] = {"Jhoel", "Adan", "Charlie", "Claudia", "Mauricio", "Daniel", "Robert"}; int index = rand() % (sizeof(names) / sizeof(string)); return names[index]; } int Game(string name) { string decide; bool hungry = false; cout << "(You role over and lay there for 45 minutes. As you do, you remember that you have a project due today and it is worth 50% of your wage for the next pay check.) "; PrintStar(); cout << "Do you get up?(yes/no):\t"; cin >> decide; PrintStar(); if (decide == "yes") { cout << "You quickly jump out of bed and get ready. You rush out the floor and start walking. You are already out of your house when you realize that you left your flash drive with some work of your project. "; PrintStar(); cout << "Would you go back?(yes/no): "; cin >> decide; PrintStar(); if (decide == "yes") return FlashGoBack(name, hungry); if (decide == "no") return Turn(name, hungry); } else cout << "Since you are already having a lot of job interviews for a better job. Why stress about a project for a job you are going to quit anyways. (End) "; return 0; } int FlashGoBack(string name, bool hungry) { cout << "(You go back and get your flash drive. However, you get to work late and your manager will ask you to leave because you have been late to work several times already) "; cout << "(End)"; return 0; } int Turn(string name, bool hungry) { cout << "(You decide not to go back and wing it, it's better to make it to your job on time to keep working on your project than arriving late to work and not be able to finish it at all) "; cout << "(End) "; return 0; } int HaveMercy(string name) { cout << "You decide to have mercy and help him to get rid of an old table from the living room. However, you got to work late and you couldn't finish your project on time. "; cout << "(End)"; return 0; }

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

Spatial Database Systems Design Implementation And Project Management

Authors: Albert K.W. Yeung, G. Brent Hall

1st Edition

1402053932, 978-1402053931

More Books

Students also viewed these Databases questions

Question

Provide examples of KPIs in Human Capital Management.

Answered: 1 week ago

Question

What are OLAP Cubes?

Answered: 1 week ago