[Help] Menu making function! menu

Shout-Out

User Tag List

Results 1 to 6 of 6
  1. #1
    Xel's Avatar ★ Elder ★
    Authenticator enabled
    Reputation
    1179
    Join Date
    Jul 2008
    Posts
    2,906
    Thanks G/R
    94/51
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    [Help] Menu making function!

    Code:
    #include <iostream>
    #include <stdlib.h>
    #include <windows.h>
    
    
    char draw_menu(char title[50], char op1[50], char op2[50], char op3[50], char op4[50])
    {
    cout << "[" << title << "]\n\n";
    cout << "1. " << op1 << endl;
    cout << "2. " << op2 << endl;
    cout << "3. " << op3 << endl;
    cout << "4. " << op4 << endl;
    }
    
    
    int main()
    {
    draw_menu("Main Menu", "Start game", "High Scores", "Help/About", "Exit");
    
    Sleep(10000);
    }
    I want to be able to add more than 4 options to draw_menu,
    but I don't want to make it look like this
    Code:
    char draw_menu(char title[50], char op1[50], char op2[50], char op3[50], char op4[50], char op5[50], char op6[50], char op7[50], char op8[50])
    What can I do?


    ANOTHER QUESTION! Is it ok to do this

    Code:
    game()
    {
    ....
    menu(); //getting back to menu so it won't exit right away
    }
    
    menu()
    {
    ...
    game();
    }
    
    
    int main()
    {
    menu();
    }
    Can I just call menu() to get back to it or should I do a while() and return a value?
    Last edited by Xel; 12-18-2009 at 08:57 AM.

    [Help] Menu making function!
  2. #2
    I Hypnotoad I's Avatar Contributor
    Reputation
    147
    Join Date
    Aug 2007
    Posts
    873
    Thanks G/R
    0/1
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I take it this is for some kind of handheld PvP script? If so.. Very nice.
    If you can wait a little bit, I could get my friend to check it out for you and see what the problem is.. if somebody doesn't reply within 8hrs at least.


    Dragon[Sky] can get into our signatures, AND our pants.



  3. #3
    jjaa's Avatar Contributor
    Reputation
    245
    Join Date
    Dec 2006
    Posts
    562
    Thanks G/R
    0/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

  4. #4
    Xel's Avatar ★ Elder ★
    Authenticator enabled
    Reputation
    1179
    Join Date
    Jul 2008
    Posts
    2,906
    Thanks G/R
    94/51
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I did not understand that website jjaa gave.

    To clarify a bit I just need a function which can be given as many words as you want
    without declaring like 100 variables or so.

    The program should create a new variable each time a new word is given for function
    draw_menu();

  5. #5
    jjaa's Avatar Contributor
    Reputation
    245
    Join Date
    Dec 2006
    Posts
    562
    Thanks G/R
    0/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Code:
    #include <stdio.h>
    #include <stdarg.h>
    #include <iostream>
    
    using namespace std;
    
    void draw_menu(char* title, ...)
    {
    
        //Declare a va_list macro and initialize it with va_start
        va_list l_Arg;
        va_start(l_Arg,title);
    
        cout << "[" << title << "]\n\n";
    
        char* val  = va_arg(l_Arg,char*);
        int i = 0;
    
        while (val != NULL)
        {
            
            cout << ++i <<". " << val << endl;
            val = va_arg(l_Arg,char*);
            
        }
        va_end(l_Arg);
    }
    
    int main()
    {
        draw_menu("Main Menu", "Start game", "Bored", "Yay");
        draw_menu("Main Menu", "Start game", "Bored", "Yay", "Again", "bored");
        draw_menu("Main Menu");
        return 0;
    }
    I haven't used C++ for a long time. But, that should give you the basic idea.

  6. #6
    Cypher's Avatar Kynox's Sister's Pimp
    Reputation
    1358
    Join Date
    Apr 2006
    Posts
    5,368
    Thanks G/R
    0/6
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Originally Posted by jjaa View Post
    Code:
    #include <stdio.h>
    #include <stdarg.h>
    #include <iostream>
    
    using namespace std;
    
    void draw_menu(char* title, ...)
    {
    
        //Declare a va_list macro and initialize it with va_start
        va_list l_Arg;
        va_start(l_Arg,title);
    
        cout << "[" << title << "]\n\n";
    
        char* val  = va_arg(l_Arg,char*);
        int i = 0;
    
        while (val != NULL)
        {
            
            cout << ++i <<". " << val << endl;
            val = va_arg(l_Arg,char*);
            
        }
        va_end(l_Arg);
    }
    
    int main()
    {
        draw_menu("Main Menu", "Start game", "Bored", "Yay");
        draw_menu("Main Menu", "Start game", "Bored", "Yay", "Again", "bored");
        draw_menu("Main Menu");
        return 0;
    }
    I haven't used C++ for a long time. But, that should give you the basic idea.
    That's how you'd do it in C.

    Doing it like that in C++ is REALLY bad. (Google it if you don't believe me, but it should be obvious why)

    Until variadic templates are added to the language (and all the mainstream compilers), your options are:
    * Pass in a container (e.g vector<string>)
    * Use operator overloading and chaining (See Boost.Format for an example)
    * Use function overloading (though you'd probably want to use the preprocessor for this, and that in itself comes with a lot of issues and pitfalls)
    * Probably something else I've forgotten

Similar Threads

  1. [ASCENT] please help me making my server public, configs inside!
    By vak in forum World of Warcraft Emulator Servers
    Replies: 10
    Last Post: 10-05-2007, 02:25 PM
  2. Help on making my Server Public!
    By Fuynuns93 in forum World of Warcraft Emulator Servers
    Replies: 4
    Last Post: 09-18-2007, 05:44 PM
  3. Replies: 10
    Last Post: 09-16-2007, 04:45 AM
  4. Help MMOwned make a new logo
    By Matt in forum Suggestions
    Replies: 77
    Last Post: 02-17-2007, 02:07 AM
  5. Help with making a grinding bot!
    By T.L. Cobra in forum World of Warcraft General
    Replies: 7
    Last Post: 02-02-2007, 01:42 AM
All times are GMT -5. The time now is 07:36 AM. Powered by vBulletin® Version 4.2.3
Copyright © 2025 vBulletin Solutions, Inc. All rights reserved. User Alert System provided by Advanced User Tagging (Pro) - vBulletin Mods & Addons Copyright © 2025 DragonByte Technologies Ltd.
Google Authenticator verification provided by Two-Factor Authentication (Free) - vBulletin Mods & Addons Copyright © 2025 DragonByte Technologies Ltd.
Digital Point modules: Sphinx-based search