Question
HOW CAN I ADD A FOR LOOP, A WHILE LOOP, AND 2 RAND()S TO THIS CODE OR HOW CAN I CHANGE THIS CODE TO ACCOMMODATE
HOW CAN I ADD A FOR LOOP, A WHILE LOOP, AND 2 RAND()S TO THIS CODE OR HOW CAN I CHANGE THIS CODE TO ACCOMMODATE THESE THINGS?
Looping Multipath Adventure
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()
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.
#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
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started