### I'm working on a text adventure

If anyone knows how to shorten this I would be greatful. Also, I'm stuck towards the end where it gives you either option 1 or 2.

 ``123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195`` ``````#include using namespace std; #include ; #include string answer, answer1, answer2, answer3, answer4, answer5, answer6, answer7, answer8, answer9, answer10; int a, b; int main() { cout << "INSRUCTIONS: This is a text adventure. You will be forced to make decisions that will ultimately decide if you live or die. Some decisions require a 'yes' or a 'no,' while others require you to type in the correct number. That is all you need to know! "<> answer; //continues after yes if (answer == "yes" || answer == "Yes") { cout << "Goodluck agent. ~END TRANSMISSION~"<> answer1; if ( answer1 == "yes" || answer1 == "Yes") { goto Beginning; } else if (answer1 == "no" || answer1 == "No") { return 0; } } else if (answer != "yes" && answer != "no") { cout << "Did you read the instructions? Either you didn't read the instructions or your just plain stupid."<> answer2; if (answer2 == "yes") { goto yes; } if (answer2 == "no") { system("CLS"); cout << "The man waves frantically. ``Get in! There's not much time!'' SHOULD YOU ENTER?"<> answer3; if (answer3 == "yes") { goto yes; } else if (answer3 == "no") { system ("CLS"); cout << "``You are making big mistake!'' he shouts. The door slams shut and the van squeals away."<> answer4; if ( answer4 == "yes" || answer1 == "Yes") { goto Beginning; } else if (answer4 == "no" || answer1 == "No") { return 0; } } else if (answer2 != "yes" && answer2 != "no") { cout << "Did you read the instructions? Either you didn't read the instructions or your just plain stupid."<> answer5; a = 1; while (a < 500) { if (answer5 == "2") //this is if answer is 2 { cout << "You rush towards the front desk and tell the clerk what happened. Armed guards are instantly scrambled and you lead them towards the place Victor became unconsious and possibly dead."<> answer1; if ( answer1 == "yes" || answer1 == "Yes") { goto Beginning; } else if (answer1 == "no" || answer1 == "No") { return 0; } } else if (answer5 != "1" && answer5 != "2") { cout << "Did you read the instructions? Either you didn't read the instructions or your just plain stupid."<= 100) { cout << "You wasted too much time and felt a prick in the back of your neck and never woke up."; } } system("PAUSE"); return 0; }``````
While it's not exactly pertinent to your question, Windows.h is a huge library to be using for a simple sleep command. I would suggest using ctime instead and building a function like

 ``1234567`` ``````void Timer(int seconds) { clock_t timer; timer = clock() + seconds * CLOCKS_PER_SEC; while (clock() < timer) {} } ``````

and if you want to wait for 3 seconds just use Timer(3);

Also, you've written your program entirely in main. While it works, it's kind of like a run on sentance. If you were to partition it into functions, it would be a) easier to read, b) easier to edit, and c)easier to follow paths). Just some suggestions
Last edited on
 Windows.h is a huge library to be using for a simple sleep command. I would suggest using ctime instead and building a function like

I would suggest not. What you're suggesting will bring your cpu to 100% utilization for no good reason, whereas Sleep does not.

What might be a reasonable replacement in C++11 is:

 ``12345678`` ``````#include #include // ... std::this_thread::sleep_for(std::chrono::milliseconds(4000)) ; // ... ``````
How do you partition it into functions? Could you please just give me an example by changing one part of my program?

Also, would it be possible to at the beginning eliminate

`string answer, answer1, answer2, answer3, answer4, answer5, answer6, answer7, answer8, answer9, answer10;`

and only have

`string answer;`

so that after every `cin <<` it would just replace the last answer? Or would that just create too many unnecessary problems? Sorry about all the questions!
Last edited on
 ``12345678910111213141516171819`` ``````#include using namespace std; #include ; #include int part1(); string answer, answer1, answer2, answer3, answer4, answer5, answer6, answer7, answer8, answer9, answer10; int a, b; int main() { if(part1() == 1) { return 0; } ...``````

 ``123456789101112131415161718192021222324252627282930313233343536373839404142434445464748`` ``````int part1() { cout << "INSRUCTIONS: This is a text adventure. You will be forced to make decisions that will ultimately decide if you live or die. Some decisions require a 'yes' or a 'no,' while others require you to type in the correct number. That is all you need to know! "<> answer; //continues after yes if (answer == "yes" || answer == "Yes") { cout << "Goodluck agent. ~END TRANSMISSION~"<> answer1; if ( answer1 == "yes" || answer1 == "Yes") { goto Beginning; } else if (answer1 == "no" || answer1 == "No") { return 1; } } else if (answer != "yes" && answer != "no") { cout << "Did you read the instructions? Either you didn't read the instructions or your just plain stupid."<

An example. Personally I like to keep my main function as empty as possible, because debugging is easier when following a path of functions.
@roger911