Hi! I’m working on my very text-adventure project in C++. It’s very simple, with no inventory system or character stats; just choose A, B, or C! Here’s the specific assignment. The problem I have is with for
loops, and getting them to do what I want them to (which is to check if the user input matches my variables, and print text based on their decision). Here’s what I have so far:
int a = 1, b = 1, c = 1;
std::cout << "Take it nice and slow? Or kick off the party loud.\n";
std::cout << " a) Stealth it\n";
std::cout << " b) Go loud\n";
std::cout << " c) Let your crew handle it\n";
for (a != 1 && b != 2 && c != 3; int++;;) {
if (a == 1 && b != 1 && c != 1;;) {
std::cin >> a;
std::cout << "There's an alley around the corner that brings\n";
std::cout << " you to a wall on the side of the building. \n";
std::cout << "There's a crack in the wall big enough to fit\n";
std::cout << "through. But the wall itself is short enough to\n";
std::cout << " rappel up over. What to do...\n\n";
std::cout << " a) Crawl through the crack in the wall\n";
std::cout << " b) Throw your grappling hook\n";
if (a == 1 && b != 1;;) {
std::cout << "Looks like the coast is clear, move up\n";
} else if (a != 1 && b == 1;;) {
std::cin >> b
std::cout << "You throw the hook over the wall.\n";
std::cout << "As it gets a firm hold on the top\n";
std::cout << "it lets out an audible CLANG.\n";
std::cout << "Nothing happens so you proceed up the wall.\n";
std::cout << "You reach the top of the wall and climb over.\n";
std::cout << "Upon landing, you turn around to find you're surrounded.\n";
std::cout << "You think to yourself how you knew you should have\n";
std::cout << "bought the wireless rappel before you're beaten.\n\n";
std::cout << " EPIC FAIL END\n";
return 0;
} else {
std::cout << "You sit there, waiting for what feels like days.\n";
std::cout << "Eventually, you die from starvation. Good job.\n";
return 0;
}
Attempting to compile this gives me:
text-adventure.cpp: In function 'int main()':
text-adventure.cpp:32:45: error: expected unqualified-id before '++' token
32 | for (a != 1 && b != 2 && c != 3; int++;;) {
| ^~
text-adventure.cpp:32:48: error: expected primary-expression before ';' token
32 | for (a != 1 && b != 2 && c != 3; int++;;) {
| ^
text-adventure.cpp:32:48: error: expected ')' before ';' token
32 | for (a != 1 && b != 2 && c != 3; int++;;) {
| ~ ^
| )
text-adventure.cpp:32:49: error: expected primary-expression before ')' token
32 | for (a != 1 && b != 2 && c != 3; int++;;) {
The extra semi-colon in the conditions is what the terminal told me to do originally.
What am I doing wrong? If you actually read through all this, thanks. It’s my first time posting in a forum so I’m not well versed in proper etiquette.