Thread: help???

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Registered User
    Join Date
    Aug 2004
    Location
    San Diego, CA
    Posts
    313
    Thanks for the clarification, Sebastiani.

    As to the OP, you can always call a menu() function from within main().. something like:

    Code:
    int main()
    {
        bool flag = 0;
    
        while (flag != 1)
        {
            menu();
        }
    
        return(0);
    }
    
    int menu()
    {
        // do stuff...
    
        if (// user says yes to some kind of "are you done" question)
        {
            flag = 1;
            return(0);
        }
    
        return(0);
    }

  2. #2
    Registered User jlou's Avatar
    Join Date
    Jul 2003
    Posts
    1,090
    Quote Originally Posted by Lithorien
    As to the OP, you can always call a menu() function from within main().. something like:
    Ummm, that won't work, flag is local to main, and won't get updated even if it compiled (it wouldn't because flag is unidentified in menu()). Maybe something more like:
    Code:
    int main()
    {
        bool flag = false;
    
        while (!flag)
        {
            flag = menu();
        }
    
        return(0);
    }
    
    bool menu()
    {
        // do stuff...
    
        if (// user says yes to some kind of "are you done" question)
        {
            return true;
        }
    
        return false;
    }

  3. #3
    Registered User
    Join Date
    Aug 2004
    Location
    San Diego, CA
    Posts
    313
    Quote Originally Posted by jlou
    Ummm, that won't work, flag is local to main, and won't get updated even if it compiled (it wouldn't because flag is unidentified in menu()). Maybe something more like:
    *blink*

    Please forgive. I have a strong head-cold and ... wow. Yeah. Or you could pass flag in the function defination (int menu(bool flag)). I think. Or just use a global variable (ick).

    Your way works though.

Popular pages Recent additions subscribe to a feed