Question: This is a program I wrote in C++. I am new to this, and can only use if else (statements? Functions? Blocks? dont know how

This is a program I wrote in C++. I am new to this, and can only use if else (statements? Functions? Blocks? dont know how to refer to it). I know for the last one isnt possible? (<-- not sure actually), so would I use a switch statement? I added comments in my code with what I am having trouble with. I have tried all the ways I've learned so far, but still can't figure it out. Could you please help? The comments are in bold.

forgot to mention I am using terminal and vim on linux

Thank you!

/**********************************************************************************************************

** Program: adventure.cpp

** Author:

** Date: 2018

** Description: Through this exciting, not in a good way, and hazardous adventure player navagates through a

quest to kill an invader in their home. Player will be asked a set of if/else statements which

will follow in options and chance to try their luck at eliminating the intruder.

** Input: user enters options on how thye want to kill spider, if they want to kill spider, and how to kill spider.

In option where user ask for help, user has no choice b/c it is by luck (to see if user has enough funds

in bank to ask sibling for help.

** Output: users options. If successful then user will continue, but if user runs in to a problem them they end up

leaving their home, and adventure ends.

***********************************************************************************************************/

#include

#include

#include

using namespace std;

void congratulations() {

cout << " Thanks to your diligence & courage, humans in your household may live to see another day *slow clap* " << endl;

exit (0);

}

void darn() {

cout << "You missed! And the spider has fled to get backup." << endl;

cout << "Aragog is now on his way! " << endl;

cout << "GAME OVER " << endl;

exit (0);

}

void ohwell() {

cout << "The spider will definitely invite their homies." << endl;

}

int main() {

float option, input, OPT, insert;

char y, n;

unsigned int bankstatement = 0;

srand (unsigned(time(0)));

bankstatement = rand()%100+5;

cout << " You are having a peaceful day when you get home and find there's a spider in your house!" << endl;

cout << "You... " << endl;

cout << "(1) Freak out. I mean straight-up panic " << "(2) Recruit backup " << "(3) Kill the thing " << "(4) Leave it for someone else and move out " << endl;

cout << "ENTER YOUR OPTION: ";

cin >> option;

if (option == 1) {

cout << " Panic -- Spiders belong NOT in homes where they could potentially crowl on you, or other humans in your household...it probably has! ~GROSS~ " << endl;

cout << "However, you feel better now, but focus! The spider is still in your house." << endl;

cout << "You... " << endl;

cout << "(2) Recruit backup " << "(3) Kill the thing " << "(4) Leave it for someone else and move out " << endl;

cout << "ENTER YOUR OPTION: ";

cin >> option;

}

if (option == 2) {

cout << " SOS -- Anybody will do. Do not attempt to be a hero and kill this monster. " << endl;

cout << "call your mom, call your dad, call your brother and sister, call your grams, call your uncles and aunties. Call EVERYONE. ";

cout << "Go on...knock on your neighboors door. " << endl << endl << endl << endl;

cout << "No one is answering! *sweat sweat* " << endl;

cout << "Do you want to wait and see if anyone comes to your help? press(y/n): ";

cin >> input; //I am having trouble with 'input'. If i enter y or n it prints out the 'if (input == y) {...}'. I only want it to print out for 'y' & not 'n'. How do i fix it?

if (input == y) {

cout << endl << " *RING RING* ";

cout << "You pick up and it's your sibling." << endl;

cout << "They inform you that they will kill the spider ONLY if you pay them, so you check your bank statement and see you have $" << bankstatement << endl;

if (bankstatement >= 55) {

cout << "Which is enough dough! Your sibling is on their way." << endl;

congratulations();

}

else if (bankstatement <= 54); {

cout << " Which is not enough, sorry. Your sibling didn't offer you a family discount either." << endl;

ohwell();

cout << n;

}

}

if (input == n) {

cout << "You... " << endl;

cout << "(3) Kill the thing " << "(4) Leave it for someone else and move out " << endl;

cout << "ENTER YOUR OPTION: ";

cin >> option; //I want it to go to the options left which are 3 and 4, but it won't let me and I don't know why. How do I fix this?

cout << endl;

}

}

if (option == 3) {

cout << " It's not about killing the spider. It's about sending a message." << endl;

cout << "Plus, there's no way that MoFo will stay in the same spot...unpredictability -- nothing's more terrifying. " << endl;

cout << "REMINDER: If there are civilian casualties along the way, so be it " << "Choose your wepon of choice: " << endl;

cout << "(1) A good ol' shoe " << "(2) Any sort of paper " << "(3) A lazer gun " << endl;

cout << "ENTER OPTION: ";

cin >> OPT;

if (OPT == 1) {

cout << endl;

darn();

}

if (OPT == 2) {

cout << "Paper it is, but do you belive polar bears belong in zoos? (press y/n): ";

cin >> insert; /*I am having trouble with this one. It won't print out 'if (insert == n)' out when I senter 'n'. This one is similar to the 'y/n' one above. Only prints out 'if (insert == y){...}' option and skips over '...insert == n...' option. */

if (insert == y) {

cout << " You grabbed plenty of toilet paper. ";

congratulations();

}

else if (insert == n) {

cout << " You can't follow through with.";

darn();

}

cout << " Jut make sure it's A LOT, so you don't touch it ~GROSS~" << endl;

congratulations();

}

if (OPT == 3) {

cout << " Shoot it, quick! " << endl << endl;

cout << "You killed it! " << ". " << ". " << ". " << "However your house is now on fire. " << ". " << ". " << ". ";

cout << "Thankfully you have coverage against the 'use of a lazer gun in case of a spider invasion'...";

congratulations();

}

}

if (option == 4) {

cout << " You knew this day would come one day, and you are ready." << endl << "You are an adult, so there's no need for explanations." << endl << "Just don't look back " << endl;

cout << endl << endl << "EVERY HUMAN FOR THEMSELVES. " << endl;

cout << " . " << ". " << ". " << endl << " You've thought it through and you can't just leave. ";

cout << "You... " << endl;

cout << "(2) Recruit backup " << "(3) Kill the thing " << "(4) Leave it for someone else and move out " << endl;

cout << "ENTER YOUR OPTION: ";

cin >> option; //I want it to go back to options 2 - 3. How would I go about that w/o making it a loop? Or is that impossible?

}

return 0;

}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!