Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7576659
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T16:58:33+00:00 2026-05-30T16:58:33+00:00

I’ve been working on a main menu to use for my text-adventure game (which

  • 0

I’ve been working on a main menu to use for my text-adventure game (which I use to learn, not to publish it), but I’m having a big problem with it. The main menu has three options, play, show the credits and terminate the program. The second option, showing the credits, needs to get the information out of credits.txt and publish this in the screen, and after the user presses a button, bring the user back to the main menu. The main menu is build as a header file (menu.h) and the main game is in test_project.cpp. I will give the full menu.h and a part of the .cpp here, plus the error of course:


Menu.h:

#ifndef MENU_H

#define MENU_H

void displayMenu () {
    int menuItem;
    bool menuRunning = true;

    while ( menuRunning ) {
        cout << "Choose a menu item:\n";

        cout << "1. Play\n2. Credits\n3. Exit\n";
        cin >> menuItem;

        switch ( menuItem ) {
            case 1:
                menuRunning = false;
                break;
            case 2:
                ifstream creditsFile("credits.txt");
                while ( !creditsFile.eof() )
                {
                    string readLine;
                    getline(creditsFile, readLine);
                    cout << readLine;                               
                }

                creditsFile.close();
                break;
            case 3:
                menuRunning = false;
                exit(0);
            default:
                cout << "";
        }

        cout << "\n---\n";
    }
}

#endif

Test_project.cpp:

#include <iostream>
#include <fstream>
#include <string>
#include <windows.h>

using namespace std;

#include "menu.h"

int main()
{
    displayMenu(); // This is where the functions from menu.h must be loaded, before the actual game starts.

    system("TITLE Title of the program comes here");

    // This is where the game starts, which loads when the user presses 1.
    int ab, cd;

And here is the error:

menu.h: In function `void displayMenu()':
In file included from test_project.cpp:11:
menu.h:29: error: jump to case label
menu.h:20: error:   crosses initialization of `std::ifstream creditsFile'
menu.h:32: error: jump to case label
menu.h:20: error:   crosses initialization of `std::ifstream creditsFile'
menu.h:29: warning: destructor needed for `creditsFile'
menu.h:29: warning: where case label appears here
menu.h:29: warning: (enclose actions of previous case statements requiring destructors in their own scope.)
menu.h:32: warning: destructor needed for `creditsFile'
menu.h:32: warning: where case label appears here
In file included from test_project.cpp:11:
menu.h:40:7: warning: no newline at end of file
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T16:58:34+00:00Added an answer on May 30, 2026 at 4:58 pm

    try to rewrite case 2 as:

    case 2:{
        ifstream creditsFile("credits.txt");
        while ( !creditsFile.eof() ){
            string readLine;
            getline(creditsFile, readLine);
            cout << readLine;                               
        }
        creditsFile.close();
        break;
    }
    

    Edit

    replace content of Menu.h with this:

    #ifndef MENU_H
    #define MENU_H
    
    void displayMenu () {
        int menuItem;
        bool menuRunning = true;
    
        while ( menuRunning ) {
            cout << "Choose a menu item:\n";
            cout << "1. Play\n2. Credits\n3. Exit\n";
            cin >> menuItem;
            switch ( menuItem ) {
                case 1:{
                    menuRunning = false;
                    break;
                }
                case 2:{
                    ifstream creditsFile("credits.txt");
                    while ( !creditsFile.eof() ){
                        string readLine;
                        getline(creditsFile, readLine);
                        cout << readLine;                               
                    }
                    creditsFile.close();
                    break;
                }
                case 3:{
                    menuRunning = false;
                    exit(0);
                }
                default:
                    cout << "";
            }
            cout << "\n---\n";
        }
    }
    #endif
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I am trying to understand how to use SyndicationItem to display feed which is
I have a text area in my form which accepts all possible characters from
I'm working with an upstream system that sometimes sends me text destined for HTML/XML
I have a jquery bug and I've been looking for hours now, I can't
I want to count how many characters a certain string has in PHP, but
For some reason, after submitting a string like this Jack’s Spindle from a text
I used javascript for loading a picture on my website depending on which small
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I would like to run a str_replace or preg_replace which looks for certain words

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.