Just need more help...

This is a discussion on Just need more help... within the C++ Programming forums, part of the General Programming Boards category; I hate starting so many threads on so many different help subjects (hipefully my threads help others to)... But my ...

  1. #1
    Registered User
    Join Date
    Aug 2004
    Posts
    731

    Just need more help...

    I hate starting so many threads on so many different help subjects (hipefully my threads help others to)...

    But my code is getting pretty big and messy. I want to know if it is possible to devide it up somehow, like in sections of code or different sheets of code (didn't know what else to call it). I think it is pretty easy doing this but of course I don't know how.

    Thanks again...

  2. #2
    & the hat of GPL slaying Thantos's Avatar
    Join Date
    Sep 2001
    Posts
    5,681
    Before you write your code layout the different steps your program will go through. Each step can be a different function. Then you just need to figure out what variables need to be passed into and returned from those functions.

  3. #3
    the Wizard
    Join Date
    Aug 2004
    Posts
    109
    Do you mean to devide it up into files or?
    Making classes and/or structures also helps..
    -//Marc Poulsen -//MipZhaP

    He sat down, he programmed, he got an error...

  4. #4
    Registered User
    Join Date
    Aug 2004
    Posts
    731
    oh I see I wasn't very clear here...

    I mean physicly devided. I guess into different files or something. So like for my rpg one could have the battling. The other could be the main menu. And so on.

  5. #5
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,796
    Modularization Theory: Each function/class does one thing. Each file does one collection of related things. Each program brings collections of things together into a whole.

    To answer your question, yes it is possible. The only real problem is making sure that shared resources are visible everywhere they need to be while still only defining them once. This is done with header files, and you can find countless threads on the topic by using a board search.
    My best code is written with the delete key.

  6. #6
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    21,588
    You could take a look at Multiple source files for one program
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  7. #7
    Registered User
    Join Date
    Aug 2004
    Posts
    731
    Maybe I won't worry about that yet...

  8. #8
    & the hat of GPL slaying Thantos's Avatar
    Join Date
    Sep 2001
    Posts
    5,681
    The first step is learning how to break this up into functions. Once you are comfortable with that breaking the functions into multiple files will be easy.

  9. #9
    Registered User
    Join Date
    Aug 2004
    Posts
    731
    well I'll just continue doing it the way I am now and when I learn more about c++ I'll come back to this subject.

  10. #10
    Registered User caroundw5h's Avatar
    Join Date
    Oct 2003
    Posts
    751
    Rune hunter, you are so intent on brute forcing your way through C++, are you sure, you don't just wanna get a book from your local libray or at least a tutorial?
    You seem to be very intelligent to grasp things and your questions are as well. I have no doubt if you gave a decent tutorial a chance you would be done it in no time and your questions would be a little more advanced as well as your code - in relation to how long it took you to learn it that is.
    Oh well, to each his own.

  11. #11
    i dont know Vicious's Avatar
    Join Date
    May 2002
    Posts
    1,200
    I had the hardest time understanding this when I first started programming.

    Let me give you a simple example...

    Lets say this file is called Functions.h
    Code:
    #ifndef _FUNCTIONS_H 
    #define _FUNCTIONS_H
    
    #include <iostream>
    
    void Func1();
    void Func2();
    
    #endif
    Now in that file you have declared prototypes for your functions.

    the #ifndef #define is what keeps the functions from being declared more than once. Its saying "Hey, if this file was already declared... nevermind!"


    Here is a file called Functions.cpp

    Code:
    #include "Functions.h"
    
    void Func1()
    {
    
        //+---Code for the function---+
    
    }
    
    void Func2()
    {
    
        std::cout << "Hello";
    
    }
    Now that file defines the functions.

    and here is main.cpp

    Code:
    //+--"Import" your functions---+
    #include "Functions.h"
    
    int main()
    {
    
        Func2(); //+---This will print "Hello" to the screen---+
    
        return 0;
    
    }
    If theres anything about that you dont understand let me know
    Last edited by Vicious; 08-29-2004 at 11:05 AM.

  12. #12
    Registered User
    Join Date
    Aug 2004
    Posts
    731
    Alright alright that is acatuly looks easy.

    Rune hunter, you are so intent on brute forcing your way through C++, are you sure, you don't just wanna get a book from your local libray or at least a tutorial?
    You seem to be very intelligent to grasp things and your questions are as well. I have no doubt if you gave a decent tutorial a chance you would be done it in no time and your questions would be a little more advanced as well as your code - in relation to how long it took you to learn it that is.
    Oh well, to each his own.
    LOL, I have read a ton of tuts. well ok 1-17 about. But in my opinion the tuts arn't the best sometimes. Oh and I don't have a local library around my area. My city pop is arund 3k lol. And I guess I am ruching this. But I sorta needed this for my game.

    Thanks alot! (I know you all hear this alot)

  13. #13
    Registered User
    Join Date
    Aug 2004
    Posts
    731
    void Func2()
    {

    std::cout << "Hello";

    }

    So why do you need the std:: in front of cout?

  14. #14
    Registered User caroundw5h's Avatar
    Join Date
    Oct 2003
    Posts
    751
    Quote Originally Posted by Rune Hunter
    So why do you need the std:: in front of cout?
    probaly cause....

  15. #15
    Registered User
    Join Date
    Aug 2004
    Posts
    731
    yay I got 100 posts LOL. But anyways I am getting this error when I try to compile this...


    Code:
    #include "Functions.h"
    
    void startprogram()
    {
    //Player varaibles
    int P_health;
    int P_level;
    int P_attack;
    int P_def;
    int P_weapon;
    int P_magiclvl;
    int P_mp;
    int P_race;
    int P_totaldamage;
    int P_dead;
    int P_exp;
    
    //Enemy variables
    int E_health;
    int E_attack;
    int E_def;
    int E_magic;   
    int E_alreadyset;
    int E_totaldamage;
    int E_dead;
    
    //Misc variables
    int monster;
    
    //Menu Misc variables
    int goagain;
    int mainmenu;
    int gamemenu;
    int gamemenu2;
    int show;
    int show2;
    
    
    
    
    
    //Start of program    
    int main();
    {    
        //Game start variables
        show2=1;
        P_level=0;
        P_exp=0;
        goagain=0;
        P_dead=0;
        E_dead=0;
        gamemenu=0;
        show=0;
        mainmenu=1;   //makes sure you go to main menu on start of program
    }    
        
    
    }
    
    void mainmenu()
    {
    
        std::cout<<"Hello";
    
    }

    This is the error I get...

    C:\Documents and Settings\Alex\Desktop\RPG Game\Makefile.win [Build Error] ["rpg] Error 1

Page 1 of 2 12 LastLast
Popular pages Recent additions subscribe to a feed

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21