I agree with your teacher that breaking the code into functions withwill help the readability of your code.
For example, haveput the code, for the result of each decision, in its own function.
cout << "1. Go West" << endl; ... if (choice2 == 1) { go_west(); } else if (choice2 == 2) { go_east(); } else if (choice2 == 3) { wait(); } If I am reading the code this makes it much easier to figure out what is happening. What happens if I input 2? I do not need to skip over all the go west or wait for something to happen code because they are in functions somewhere else. If I am interested in that code then I look at the function.
This also helps if two routes lead to the same result, you do not need to copy and paste the code you simply call the same function.
If you have learned about switch statements then it might get you some more points to use a switch instead of if/else.
switch (choice2) { case 1: go_west(); break; case 2: go_east(); break; case 3: wait(); break; } This is not very important in the real world though. Use whichever you think looks better.
It would also be an idea to use enumsenums or constant values when processing the decision points. If iI look at the if/else statments Istatements I need to rememeberremember: does 1 mean east or west?
#define WEST 1 #define EAST 2 #define WAIT 3 if (choice2 == WEST) { go_west(); } else if (choice2 == EAST) { go_east(); } else if (choice2 == WAIT) { wait(); } A more advanced strategy would be to use a jump table.
void(*tbl[4])(void) = { &invalid_input, &go_west, &go_east, &wait }; cin >> choice2; if (choice2 > 3) choice2 = 0; tbl[choice2](); This may not be a viable option for you at your current stage but it might help other people or yourself later on in your education.