I have some menu problems. So this is my first time, and I need someone to please solve the problem for me.
This is my program. When I ask it to enter on the home menu, it takes me back to the second menu and asks me again if I would like to exit. Could someone help me. Get rid of this problem. Please someone help me.

#include <iostream>
using namespace std;
int main()
{

    int choice;
    bool gameOn = true;
    while (gameOn != false) {
        cout << "\n\t\tWelcome To Zoheb.I.Currimbhoy's Age Calculator\n";
        cout << " \n\n1 - Start the Questionaire.\n";
        cout << " \n2 - Exit.\n";
        cout << " \nEnter your choice and press return: ";
        cin >> choice;

        switch (choice) {
        case 1:
            cout << "\n\n\t\t\t\tStart The Questionaire\n";
            int birthmonth,birthyear;
            int currentmonth,currentyear;
            int agey,agem;
            cout<<"\n\n\t\tUsing C++, Find Your Age By Answering The Questions\n\n";
            cout<<"\n\nEnter Your Birth Year(Eg:1989):";
            cin>>birthyear;
            cout<<"\n\nEnter Your Birth Month(Eg:7):";
            cin>>birthmonth;
            cout<<"\n\nEnter The Current Month(Eg:7):";
            cin>>currentmonth;
            cout<<"\n\nEnter The Current Year(Eg:2010):";
            cin>>currentyear;
            agey=currentyear-birthyear;
            agem=currentmonth-birthmonth;
            cout<<"\n\n\t\t\tYour Age is "<<agey<<" Years And "<<agem<<" Months ";
            printf("\n\n\n\t Thanks for using the age calculator. Have a great day.\n");
            break;
        case 2:
            cout << "End of Program.\n";
            gameOn = false;
            break;
        default:
            cout << "Not a Valid Choice. \n";
            cout << "Choose again.\n";
            cin >> choice;
            while (gameOn!=false);

            bool gameOn = true;
            while (gameOn != false) {
                cout << " \n\n1- Re-Start the Questionaire.\n";
                cout << " \n\n2- Exit.\n";
                cout << " \nEnter your choice and press return: ";
                cin >> choice;
                switch (choice) {
                case 1:
                    cout << "\n\n\t\t\t\tStart The Questionaire\n";
                    int birthmonth,birthyear;
                    int currentmonth,currentyear;
                    int agey,agem;
                    cout<<"\n\n\t\tUsing C++, Find Your Age By Answering The Questions\n\n";
                    cout<<"\n\nEnter Your Birth Year(Eg:1989):";
                    cin>>birthyear;
                    cout<<"\n\nEnter Your Birth Month(Eg:7):";
                    cin>>birthmonth;
                    cout<<"\n\nEnter The Current Month(Eg:7):";
                    cin>>currentmonth;
                    cout<<"\n\nEnter The Current Year(Eg:2010):";
                    cin>>currentyear;
                    agey=currentyear-birthyear;
                    agem=currentmonth-birthmonth;
                    cout<<"\n\n\t\t\tYour Age is "<<agey<<" Years And "<<agem<<" Months ";
                    printf("\n\n\n\t Thanks for using the age calculator. Have a great day.\n");
                    break;
                case 2:
                    cout << "End of Program.\n";
                    gameOn = false;
                    break;
                default:
                    cout << "Not a Valid Choice. \n";
                    cout << "Choose again.\n";
                    cin >> choice;
                    break;
                    while(gameOn!=false);
                    return 0;
                }
                while (gameOn!=false);
            }
        }
        return (0);
    }
}

This is my program. When I ask it to enter on the home menu, it takes me back to the second menu and asks me again if I would like to exit. Could someone help me. Get rid of this problem.

Why do you have a nested while() and then another nested switch()? Why not just loop again after detecting the first invalid input? I suspect this is why you're receiving the same prompt, twice. You're only returning from the nested while(), not the overall while().

Consider changing the default case in your first switch() to re-prompt the user ... I'm betting this will get you what you're looking for.

>>Could someone help me. Get rid of this problem.
This isn't what we do.

>>Could someone help me get rid of this problem?
This is what we do.

Hey it still doesnt work.

#include <iostream>
using namespace std;
int main()
{
 
    int choice;
    bool gameOn = true;
     (gameOn != false) {
        cout << "\n\t\tWelcome To Zoheb.I.Currimbhoy's Age Calculator\n";
        cout << " \n\n1 - Start the Questionaire.\n";
        cout << " \n2 - Exit.\n";
        cout << " \nEnter your choice and press return: ";
        cin >> choice;
 
        switch (choice) {
        case 1:
            cout << "\n\n\t\t\t\tStart The Questionaire\n";
            int birthmonth,birthyear;
            int currentmonth,currentyear;
            int agey,agem;
            cout<<"\n\n\t\tUsing C++, Find Your Age By Answering The Questions\n\n";
            cout<<"\n\nEnter Your Birth Year(Eg:1989):";
            cin>>birthyear;
            cout<<"\n\nEnter Your Birth Month(Eg:7):";
            cin>>birthmonth;
            cout<<"\n\nEnter The Current Month(Eg:7):";
            cin>>currentmonth;
            cout<<"\n\nEnter The Current Year(Eg:2010):";
            cin>>currentyear;
            agey=currentyear-birthyear;
            agem=currentmonth-birthmonth;
            cout<<"\n\n\t\t\tYour Age is "<<agey<<" Years And "<<agem<<" Months ";
            printf("\n\n\n\t Thanks for using the age calculator. Have a great day.\n");
            break;
        case 2:
            cout << "End of Program.\n";
            gameOn = false;
            break;
        default:
            cout << "Not a Valid Choice. \n";
            cout << "Choose again.\n";
            cin >> choice;
             (gameOn!=false);
 
            bool gameOn = true;
             (gameOn != false) {
                cout << " \n\n1- Re-Start the Questionaire.\n";
                cout << " \n\n2- Exit.\n";
                cout << " \nEnter your choice and press return: ";
                cin >> choice;
                switch (choice) {
                case 1:
                    cout << "\n\n\t\t\t\tStart The Questionaire\n";
                    int birthmonth,birthyear;
                    int currentmonth,currentyear;
                    int agey,agem;
                    cout<<"\n\n\t\tUsing C++, Find Your Age By Answering The Questions\n\n";
                    cout<<"\n\nEnter Your Birth Year(Eg:1989):";
                    cin>>birthyear;
                    cout<<"\n\nEnter Your Birth Month(Eg:7):";
                    cin>>birthmonth;
                    cout<<"\n\nEnter The Current Month(Eg:7):";
                    cin>>currentmonth;
                    cout<<"\n\nEnter The Current Year(Eg:2010):";
                    cin>>currentyear;
                    agey=currentyear-birthyear;
                    agem=currentmonth-birthmonth;
                    cout<<"\n\n\t\t\tYour Age is "<<agey<<" Years And "<<agem<<" Months ";
                    printf("\n\n\n\t Thanks for using the age calculator. Have a great day.\n");
                    break;
                case 2:
                    cout << "End of Program.\n";
                    gameOn = false;
                    break;
                default:
                    cout << "Not a Valid Choice. \n";
                    cout << "Choose again.\n";
                    cin >> choice;
                    break;
                    (gameOn!=false);
                    return 0;
                }
                gameOn!=false;
            }
        }
        return (0);
    }
}

Please remember to use code tags. It makes helping you much easier. I think you need to adjust how you're closing your { } throughout your program. What specifically isn't working now?

Edit: What did you change from last time? This looks exactly the same ... ?

I may start just deleting posts that fail to use code tags. :@

commented: Can we? Please? :hopeful: +17

Why the need to mix cout and printf?

Why did you remove all the while keywords in the second post?

Back to your 1st post:

I have some menu problems. So this is my first time, and I need someone to please solve the problem for me.

We don't solve things for you. We help you solve them yourself.

I need someone to please solve the problem for me.
Could someone help me. Get rid of this problem. Please someone help me.
== code ==
Could someone help me. Get rid of this problem.

4 times is begging. And if you think about it, isn't posting "HELP" on a help board redundant?


Why did you copy your program into the default case of the first switch? Just let the default go without changing gameOn -- two lines. And what's with that last while() loop that does nothing?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.