Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

How would I modify this code to add these loops and rands? Modify your Multipath Adventure from the previous lab to fulfill the following requirements:

How would I modify this code to add these loops and rands?

Modify your Multipath Adventure from the previous lab to fulfill the following requirements:

  • Use at least 1 for loop
  • Use at least 1 while loop
  • Use at least 2 instances of rand()

(If your code already fulfilled these requirements, 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.

As part of grading your lab, 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.

Hints: Possible uses of a for loop might include events that occur in sequence, such as a stopwatch ticking off seconds or a group of travelers emerging from the forest one by one. A while loop might comprise part of the game that repeats itself until a specific action is taken.

Additional Requirement

  • You must develop this lab in CLion, an Integrated Development Environment (IDE), and then copy over your working version to zyBooks for submission and pass-off. Experiencing an IDE is one of the learning outcomes of this class, and is required for this lab. State in the Canvas submission quiz whether you exclusively used CLion to develop this lab, and Canvas will give you the points automatically. We encourage you to use CLion for developing the rest of the labs in this class.

Deductions Graded by TAs

  • Adherence to the style guidelines. (up to 10 points)
  • All deductions from the previous Multipath Adventure Labs
    • It is fine if you re-organize your code and have different paths than you did in Lab 3, or different functions than you did in Lab 4, but make sure that you still meet the requirements as listed in Labs 3 and 4.
  • You must have at least 1 for loop in your code (15 points)
  • You must have at least 1 while loop in your code (15 points)
  • You must have at least 2 instances of rand() in your code (5 points per missing rand() instance)
  • Your code must correctly follow the paths outlined in your decision tree (15 points per path that does not work correctly)
    • This includes terminating properly at the end of a path - if you need to end the program early at any point in your code, you can use the command exit(0); to end your program at any point

#include #include #include using namespace std;

//function with return value string getChoice1() { string choice1; cout << "You wake up in the morining knowing you have football practice after school, so you decide to... " << endl; cout << "a. Get ready and skip breakfast." << endl; cout << "b. Eat breakfast knowing that it fuels your body." << endl; cin >> choice1; return choice1; }

string getChoice4() { string choice4; cout << "You drive to school hungry and it gets to lunch time and you're starving. You decide to... " << endl; cout << "a.Eat until you are full." << endl; cout << "b. Eat a moderate amount." << endl; cin >> choice4; return choice4; }

void getChoice5(string choice4,string &choice5) {

if (choice4 == "a") { cout << "You arrive at practice while you are full so you decide to..." << endl; cout << "a. Tell Coach G that you are sick." << endl; cout << "b. Practice." << endl; cin >> choice5; } }

void getChoice2(string &choice2) { cout << "You get in the car to drive to school, you feel good. "; cout << "Time passes and now it is lunch time and you are not hungry. You decide to... " << endl; cout << "a. Eat moderatley. " << endl; cout << "b. Not eat at all." << endl; cin >> choice2; }

void getChoice3(string &choice3) { cout << "You don't have enough energy to practice. So you decide to..." << endl; cout << "a. Practice." << endl; cout << "b. Go home." << endl; cin >> choice3; }

int main () {

string choice1; string choice2; string choice3; string choice4; string choice5;

choice1 = getChoice1(); if (choice1 == "a") { choice4 = getChoice4(); }

getChoice5(choice4,choice5); if (choice5 == "a") { cout << " You get to go home. THE END." << endl; } else { cout << "You end up throwing up then you go home. THE END." << endl; } if (choice5 == "a") { cout << "end" << endl; } else { cout << "You don't have enough energy because you are hungry and pass out during practice."; cout << "You then end up going home. THE END." << endl; } if (choice1 == "a") { cout << endl; } else { getChoice2(choice2); if (choice2 == "b") { getChoice3(choice3); if (choice3 == "b") { cout << "You pass out." << endl; } else { cout << "You feel good." << endl; } } else { cout << "You have a good practcie." << endl; } }

}

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 For Advanced Applications 18th International Conference Dasfaa 2013 Wuhan China April 22 25 2013 Proceedings Part 2 Lncs 7826

Authors: Weiyi Meng ,Ling Feng ,Stephane Bressan ,Werner Winiwarter ,Wei Song

2013th Edition

3642374492, 978-3642374494

More Books

Students also viewed these Databases questions

Question

1. Identify six different types of history.

Answered: 1 week ago

Question

2. Define the grand narrative.

Answered: 1 week ago

Question

4. Describe the role of narratives in constructing history.

Answered: 1 week ago