Thread: rand() problem, plz help!

  1. #16
    (?<!re)tired Mario F.'s Avatar
    Join Date
    May 2006
    Location
    Ireland
    Posts
    8,446
    To add another reason, globals don't go out of scope. They are not destroyed. They exist across the entire code and during the entire lenght of the program. Your program, if of medium size, will probably exhaust all its available memory.
    Originally Posted by brewbuck:
    Reimplementing a large system in another language to get a 25% performance boost is nonsense. It would be cheaper to just get a computer which is 25% faster.

  2. #17
    Just Lurking Dave_Sinkula's Avatar
    Join Date
    Oct 2002
    Posts
    5,005
    Quote Originally Posted by swgh
    Global variables make it very hard to keep track of when it is changing its value and where it changes, say you had a file of 2000 lines of code. And you wanted to keep track of a certain variable at a certain point, ie: when did it chnage its value from a=1 to a=5? It would take ages to find out.
    That hits too close to home! (Job hazard -- but an underestimate to the number of lines of code.)
    7. It is easier to write an incorrect program than understand a correct one.
    40. There are two ways to write error-free programs; only the third one works.*

  3. #18
    (?<!re)tired Mario F.'s Avatar
    Join Date
    May 2006
    Location
    Ireland
    Posts
    8,446
    regular expressions. pray tell your editor has it or you have some external tool
    Originally Posted by brewbuck:
    Reimplementing a large system in another language to get a 25% performance boost is nonsense. It would be cheaper to just get a computer which is 25% faster.

  4. #19
    Registered User Wylde's Avatar
    Join Date
    Sep 2006
    Posts
    10
    Ok, I'll try to stay away from using globals as much as possible . Sorry for all the stupid questions, and thanks alot for answering them. I just got a book on C++ yesterday and havent put it down since lol. So Im just startin out, but I want to learn to program efficiently now, and Im hoping these forums will help me do that. Thanks alot!

  5. #20
    Just Lurking Dave_Sinkula's Avatar
    Join Date
    Oct 2002
    Posts
    5,005
    Quote Originally Posted by Mario F.
    regular expressions. pray tell your editor has it or you have some external tool
    [Heading a bit off-topic...]I'm stuck with CodeWright right now (and the vendor IDE which are both okay), but fighting for SlickEdit which both do -- but there's a twist: half of it is still in assembly, so sometimes the names don't match their C names. And some assembly macros for variable definitions (some not). It's fun (not).
    7. It is easier to write an incorrect program than understand a correct one.
    40. There are two ways to write error-free programs; only the third one works.*

  6. #21
    Its hard... But im here swgh's Avatar
    Join Date
    Apr 2005
    Location
    England
    Posts
    1,688
    Ok, here is some advice.

    # learn as much C++ as you can

    # code till your eyes fall out

    # do not switch to game programmng books untill you are ok in using the following topics:

    *classes ( very important in game programming )
    *functions
    *pointers ( important )
    *references
    *arrays - including vectors, iterators, algorithms ( used for sorting )
    *memory managment, the use of new and delete keywords
    *debugging - using throw and catch exceptions
    *code maintence

    It seems alot, and it is. You have to have at the very minimum a breif understanding of most if not all the above before I would consider game progamming books. If you learn the above, and are confident in the use of it ( this takes time - but also great fun ) you will have taken a great step to learning some of the most important issues in game programming. A good book(s) help to, a few I recomend are: C++, how to program 5th edition and beginning C++ game programming by Micheal morrison.

    Finally, good luck -- if you need any advise, come on the boards and we are happy to help

  7. #22
    Registered User Wylde's Avatar
    Join Date
    Sep 2006
    Posts
    10

    Unhappy

    I accidently deleted this post.... lol ya Im pretty dumb, anyways, Im gonna repost it so it doesnt look like the guy that replied(thank you!) didnt make sense, and incase someone else wants to reply. Sorry =/

    Ive got 1 more question, and I dont think its worth makin a whole new thread, so I'll just post it here. Im 16 years old, 17 in 3 months, and I plan on getting a degree in computer science after I graduate highschool. So I figured it would be good for me to learn to program now. My long-term goal is to get a job as a game programmer, but right now I just want to learn C++ since that is obviously very important. So I got the first book in this list. Im about half way through it and so far its been pretty helpful and I have made alot of progress. Once im done with that book I plan on continuing through the list, but Im not sure when(if ever) I should switch my focus from strictly C++ to game programming. I appreciate any advice, and Id rather get sent down the right path now, instead of wasting my time learning something im never gonna use. Thanks in advance =)

  8. #23
    Its hard... But im here swgh's Avatar
    Join Date
    Apr 2005
    Location
    England
    Posts
    1,688
    see above for a suggestion ^^

  9. #24
    Registered User Wylde's Avatar
    Join Date
    Sep 2006
    Posts
    10

    Question

    Ya I just noticed that someone replied, lol sry. Thanks for the advice, Ill read as many books on C++ and mess around with it as much as I can, but how long do you think it will take to get a good understanding on all those topics you listed, for the average person I mean, but I do have alot of free time that I can devote to it, so maybe I can do it a little faster than the average person =P

  10. #25
    Its hard... But im here swgh's Avatar
    Join Date
    Apr 2005
    Location
    England
    Posts
    1,688
    A breif look at memory management for you:

    Code:
    #include <iostream>
    
    using std::cout;
    using std::cin;
    
    class Myclass
    {
    public:
        Myclass();
        ~Myclass();
    
        int getval() const { return *val; }
    
    private:
        int *val;
    };
    
    Myclass::Myclass()
    {
       val = new int(5);
    }
    
    Myclass::~Myclass()
    {
       delete val;
       val = NULL;
    }
    
    int main ( void )
    {
       Myclass *mc = new Myclass;
    
       cout << "Value of val is: " << mc->getval();
    
       delete mc;
       mc = NULL;
    
       cin.get();
    
       return 0;
    }
    This a breif example of pointers and memory on the heap

  11. #26
    Its hard... But im here swgh's Avatar
    Join Date
    Apr 2005
    Location
    England
    Posts
    1,688
    It all depends on how quicky you learn and pick it up. Remember, it is not just a case of copying the code and compiling itm you know the book code works. The idea and most important thing is to try things on your own. it took me ages to work out how pointers worked, but I got there in the end. Remeber, the compiler is your friend, it will help you! As will all of us here

  12. #27
    Its hard... But im here swgh's Avatar
    Join Date
    Apr 2005
    Location
    England
    Posts
    1,688
    Im off now, il view this thread tommorrow... hope my advice was useful to you.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. can any1 plz make this assignment
    By jean in forum C Programming
    Replies: 17
    Last Post: 05-13-2009, 09:19 PM
  2. plz help me...
    By sweetchakri in forum C Programming
    Replies: 1
    Last Post: 03-03-2009, 11:50 PM
  3. [Request] Need Help Plz
    By TylerD in forum Tech Board
    Replies: 4
    Last Post: 01-03-2009, 09:54 AM
  4. Anyone plz help me
    By Rose_Flowers in forum A Brief History of Cprogramming.com
    Replies: 1
    Last Post: 09-17-2003, 12:01 PM
  5. help plz plz
    By nsssn73 in forum C++ Programming
    Replies: 2
    Last Post: 06-03-2002, 08:44 AM