0

I am currently struggling to problem solve. I need to make my text based comment for entering a room, different the second time I enter that same room and get an object that first time. My code is formatted a little wrong but it looks like this.

#include<iostream>
using namespace std;

void print_menu();

int main()
{
 int choice, valid_choice;
 do{
        print_menu();
        cin >> choice;
        valid_choice = 1;
        switch(choice){
        case 0:
               break;
        case 1:
               cout << endl <<  "Currently In Room 1" << endl;
               cout << endl << "This room is just white! Kinda impressive how white it is..." <<endl;
               break;
        case 2:
               cout << endl << "Currently In Room 2" << endl;
               cout << endl << "This room is just white! Kinda impressive how white it is..." <<endl;
               break;
        case 3:
               cout << endl << "Currently In Room 3" << endl;
               cout << endl <<"It's too dark to even see the color of the walls in this room!"<<endl;
               break;
        case 4
               cout << endl << "Currently In Room 4" << endl;
               cout << endl << "This seems familiar???" << endl;
               break;
        default:
               valid_choice = 0;
               cout << "That is not a room..." << endl;
        }
        if(valid_choice && (choice !=0)){
               cout << endl << "Now which room will we try?" <<  endl;
        }
  }while(choice != 0);
  return 0;
}
 void print_menu(){
   enter code here cout << endl;
    cout << "Enter Room 1 (1)" << endl;
    cout << "Enter Room 2 (2)" << endl;
    cout << "Enter Room 3 (3)" << endl;
    cout << "Enter Room 4 (4)" << endl;
    cout << "Exit Game (0)" << endl;
    cout << "Enter A Room";
}

Im not sure how to use these global and static variables to get different results the more I enter the same room.

3dited
  • 1

1 Answers1

0

There is no problem with your code logically. There is a minor syntax error. Everything else is good.

Just add the colon(:) at the end of "case 4" of the switch case statements. I am posting the fully-functioning code below:

#include<iostream>
    using namespace std;
    
    void print_menu();
    
    int main()
    {
     int choice, valid_choice;
     do{            
            print_menu();
            cin >> choice;
            valid_choice = 1;
            switch(choice){
            case 0:
                   break;
            case 1:
                   cout << endl <<  "Currently In Room 1" << endl;
                   cout << endl << "This room is just white! Kinda impressive how white it is..." <<endl;
                   break;
            case 2:
                   cout << endl << "Currently In Room 2" << endl;
                   cout << endl << "This room is just white! Kinda impressive how white it is..." <<endl;
                   break;
            case 3:
                   cout << endl << "Currently In Room 3" << endl;
                   cout << endl <<"It's too dark to even see the color of the walls in this room!"<<endl;
                   break;
            case 4:
                   cout << endl << "Currently In Room 4" << endl;
                   cout << endl << "This seems familiar???" << endl;
                   break;
            default:
                   valid_choice = 0;
                   cout << "That is not a room..." << endl;
            }
            if(valid_choice && (choice !=0)){
                   cout << endl << "Now which room will we try?" <<  endl;
            }
      }while(choice != 0);
      return 0;
    }
     void print_menu(){
        cout << endl;
        cout << "Enter Room 1 (1)" << endl;
        cout << "Enter Room 2 (2)" << endl;
        cout << "Enter Room 3 (3)" << endl;
        cout << "Enter Room 4 (4)" << endl;
        cout << "Exit Game (0)" << endl;
        cout << "Enter A Room";
    }