Build a Text Adventure: I'm trying to figure out where can I place a for loop and error message

#include <iostream>

int main () {

std::cout << "You walk into a bar and scan the room \n";
std::cout<< "You see your buddies from work on one corner. \n";
std::cout<< "You see a girl drinking alone in another corner. \n";
std::cout<< "You also see a table to sit by yourself. \n \n";

    std::cout << " What should you do? \n";
    std::cout << " A) Sit alone \n";
    std::cout << " B) Sit with buddies \n";	
    std::cout << " C) Sit with girl \n";
    std::cout << " D) Go Home \n\n";
    char answer;
    std::cin >> answer;

if ((answer == 'A') || (answer == 'a')) {
  std::cout << "You're drinking alone now \n";
else if ((answer == 'B') || (answer == 'b')) {
std::cout << "Say whats up to you're buddies. What will you do now? \n";
else if ((answer == 'C') || (answer == 'c')) {
std::cout << "Say something to her! \n";
else if ((answer == 'D') || (answer == 'd')) {
std::cout << "Have a nice trip home. \n";
else if {
std::cout << "Redo Question \n";
return 0;


So far this is the code I have written. I’m trying to figure out where can I put a for loop into something like this.
I’m also having issue with compiling it. I keep getting this error message:

text-adventure.cpp:34:9: error: expected ‘(’ before ‘{’ token
 else if {

Compiler issue is down to that fact that else if expects some form of conditional expression, else if (what?). Perhaps you meant something other than else if?

What do you mean where you can you put a for loop? Is this an instruction in the lesson, it’d be worth linking the lesson if so. I’d hazard a guess you’d want to be wrapping your input and at least some of those selections in some form of loop so the phrases like “What will you do now?” allow additional selections but that is a guess.

Build a Text Adventure
This project is slightly different than others you have encountered thus far on Codecademy. Instead of a step-by-step tutorial, this project contains a series of open-ended requirements which describe the project you’ll be building. There are many possible ways to correctly fulfill all of these requirements, and you should expect to use the internet, Codecademy, and other resources when you encounter a problem that you cannot easily solve.

Project Goals
Create a C++ text adventure with the storyline of your choosing. The program should use your knowledge of C++ conditionals, logic, and loops.

That is the assignment.

What I was trying to do was have the user input the answer by typing the answer ‘A’ ‘B’ etc . I don’t know if it matters, but I also wanted to include uppercase or lowercase as a choice and I thought that ((answer == ‘C’) || (answer == ‘c’)) would do that.

The if or else if I thought it would have help with the option of choosing. But if there is a better way of choosing. I’m here to learn.

Also yes the for loop was to be included into this assignment. But wasn’t sure how that would be included into something like this assignment, which I feel is more like a multiple choice question.

It seems to be quite open-ended, I wasn’t criticising the use of if statements but the attempt to use an elif if without a boolean condition, that is:

else if (x == 3) {
    // this is fine
else if {
    // !! stynax error here
else {
    // an else works without a condition

Seems like it is up to you on how how you incorporate the loop. My first thought would to use a loop to repeatedly get user input so that after making a decision and observing the outcome you have a new decision to make. But it seems to be entirely up you. You could work off that suggestion, or, better still; get creative :slightly_smiling_face:

1 Like

How can I create something where people can type in answer using an alphabet instead of a number. And then have them follow up with another question? Would I use and if and else statement?