Thread: Any Tips on learning C++??

  1. #1
    Registered User
    Join Date
    May 2010
    Posts
    70

    Post Any Tips on learning C++??

    Hello,I'm 15 and currently im trying to learn C++ because its gonna go towards my career in game development.I've bought the book: "C++ for dummies 7 in 1" and im quite pleased with it.I've been reading it the whole day for 3 days now(no im not a nerd,dork,geek)and i've tried to make my own programs using the skills taught by the book to enforce the skills i've learned.


    I try to reread sections or chapters to make sure i learn them before i move on.Recently i've been trying to code on paper to help me with errors because i wont have the compilers help to tell whats wrong.Other than all these things i've been doing are there any other tips from people who work for the game industry or are an expert in programming.I'd really appreciate it being that its going to help me in pursuing a career in game programming.

    Thank you.

  2. #2
    Registered User NeonBlack's Avatar
    Join Date
    Nov 2007
    Posts
    431
    Books can be very helpful, but you will learn much more by doing than you will from any book. Why don't you attempt something ambitious? Write a full game- it doesn't have to be fancy (a console version of battleship for example). Ask questions when you get stuck.
    I copied it from the last program in which I passed a parameter, which would have been pre-1989 I guess. - esbo

  3. #3
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    Practice, practice, practice.

    Start simple, say
    tic-tac-toe, console, 1-player against random computer moves, then add incrementally
    + simple defensive strategy for computer (it doesn't lose for dumb mistakes)
    + smart offensive strategy for computer (you lose on any mistake)
    + 2 human players with "hints" help feature
    + scoreboard, win/loss/best time etc
    + improve graphics to a simple GUI
    + sound effects
    + 3D graphics (not really, but a fun thing to do along the way)
    + network mode to challenge your remote friends

    Each builds on the previous one.

    All of the code will change over the entire series, but each incremental step should be a transition rather than a rewrite.


    > because i wont have the compilers help to tell whats wrong.
    Why not? Are you camping out in the woods?
    There are plenty of free compiler options available.

    Writing the code on paper won't teach you much at all.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  4. #4
    Registered User
    Join Date
    May 2010
    Posts
    70
    Quote Originally Posted by Salem View Post
    Practice, practice, practice.

    Start simple, say
    tic-tac-toe, console, 1-player against random computer moves, then add incrementally
    + simple defensive strategy for computer (it doesn't lose for dumb mistakes)
    + smart offensive strategy for computer (you lose on any mistake)
    + 2 human players with "hints" help feature
    + scoreboard, win/loss/best time etc
    + improve graphics to a simple GUI
    + sound effects
    + 3D graphics (not really, but a fun thing to do along the way)
    + network mode to challenge your remote friends

    Each builds on the previous one.

    All of the code will change over the entire series, but each incremental step should be a transition rather than a rewrite.


    > because i wont have the compilers help to tell whats wrong.
    Why not? Are you camping out in the woods?
    There are plenty of free compiler options available.

    Writing the code on paper won't teach you much at all.
    Oh you dont get it,i do use a compiler, i just write code on paper sometimes before i type it into the compiler and compile to improve my programming skills.

    @NeonBlack: I'm on classes right now, page like 140/800, im am a VERY ambitious guy but, without learning everything i wont be able to make a fully functional game RIGHT NOW but, as i get into the lets say 300-400 page sections ill start writing programs that are simple but, not super simple.After learning classes ill open my options on what i can code because classes are a very useful thing.

    @Salem: I dont know how to write offensive strategy and all that stuff yet.It's not that im not ambitous, its just that i dont have enough tools to be able to do it.

  5. #5
    In the Land of Diddly-Doo g4j31a5's Avatar
    Join Date
    Jul 2006
    Posts
    476
    You want to be a game developer but is not a geek? .......... right.........

    There's no need to be ashame to admit that you're a geek. I actually even quite proud to be one. I've got tons of animes and mangas in my home, play lots of games, I even downloaded lots of abandonwares, trying open source engines, etc. Yeah I'm a geek, so what. :P

    Ok, actually the best way to learn programming is by copying others. What I meant wasn't about copy-pasting the whole code, but by seeing lots of other people's code. Try to understand the flow and architecture of each code. Try to learn about their style of coding and develop your own. Any code will do. A bad code is as important as a good one. Fortunately there are tons of open source projects out there. You can start there.

    About the game development issue, you can see this old article from GameDev.net to get you started: GameDev.net -- How do I make games? A Path to Game Development

    And also you can see all of these articles as well for starting a career in game dev: GameDev.net - For Beginners

    Good luck and Godspeed...
    Last edited by g4j31a5; 07-01-2010 at 12:12 AM.
    ERROR: Brain not found. Please insert a new brain!

    “Do nothing which is of no use.” - Miyamoto Musashi.

  6. #6
    In the Land of Diddly-Doo g4j31a5's Avatar
    Join Date
    Jul 2006
    Posts
    476
    *double post*
    Last edited by g4j31a5; 07-01-2010 at 12:12 AM. Reason: DOUBLE POST
    ERROR: Brain not found. Please insert a new brain!

    “Do nothing which is of no use.” - Miyamoto Musashi.

  7. #7
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    Quote Originally Posted by cuo741 View Post
    Oh you dont get it,i do use a compiler, i just write code on paper sometimes before i type it into the compiler and compile to improve my programming skills.
    You can write logic on paper, but writing the actual code on paper is just silly. The compiler is there to help you. Use it.

    @Salem: I dont know how to write offensive strategy and all that stuff yet.It's not that im not ambitous, its just that i dont have enough tools to be able to do it.
    No one said you should do it right away. If you want to be a game dev, then you should probably learn it sometime. So just focus on what you can, get new books and resources, learn more, and continue extending your application. That's the idea.

    And while looking at other source helps to a certain degree, the only way to get really good is simply to practice writing your own programs. Take note of how others do, and why, then apply that knowledge to your own programs.
    Now do that for a couple of years and you'll become an expert, too. No shortcuts.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  8. #8
    Ugly C Lover audinue's Avatar
    Join Date
    Jun 2008
    Location
    Indonesia
    Posts
    489
    My only and only tips is just learn to learn and exploit preexisting application/code.
    Just GET it OFF out my mind!!

  9. #9
    Registered User
    Join Date
    May 2010
    Posts
    70
    Quote Originally Posted by g4j31a5 View Post
    You want to be a game developer but is not a geek? .......... right.........

    There's no need to be ashame to admit that you're a geek. I actually even quite proud to be one. I've got tons of animes and mangas in my home, play lots of games, I even downloaded lots of abandonwares, trying open source engines, etc. Yeah I'm a geek, so what. :P

    Ok, actually the best way to learn programming is by copying others. What I meant wasn't about copy-pasting the whole code, but by seeing lots of other people's code. Try to understand the flow and architecture of each code. Try to learn about their style of coding and develop your own. Any code will do. A bad code is as important as a good one. Fortunately there are tons of open source projects out there. You can start there.

    About the game development issue, you can see this old article from GameDev.net to get you started: GameDev.net -- How do I make games? A Path to Game Development

    And also you can see all of these articles as well for starting a career in game dev: GameDev.net - For Beginners

    Good luck and Godspeed...
    Umm could you give me a link to these open source projects???Like simple ones?Not to complicated and all if you could that would be great!

  10. #10
    spurious conceit MK27's Avatar
    Join Date
    Jul 2008
    Location
    segmentation fault
    Posts
    8,300
    Quote Originally Posted by Elysia View Post
    You can write logic on paper, but writing the actual code on paper is just silly. The compiler is there to help you. Use it.
    DITTO! One of the worst (if not the worst) mistakes I see here by beginners is writing code without compiling it. It is simply too easy for people to compound mistakes because they don't know they are mistakes, and then they build upon a rotten foundation.

    Bad habit. Don't.

    Quote Originally Posted by cuo741 View Post
    Umm could you give me a link to these open source projects???Like simple ones?Not to complicated and all if you could that would be great!
    You should join Game.dev and ask there, that's what it's for. Notice they have forums like here:
    GameDev.Net Discussion Forums
    C programming resources:
    GNU C Function and Macro Index -- glibc reference manual
    The C Book -- nice online learner guide
    Current ISO draft standard
    CCAN -- new CPAN like open source library repository
    3 (different) GNU debugger tutorials: #1 -- #2 -- #3
    cpwiki -- our wiki on sourceforge

  11. #11
    Registered User
    Join Date
    May 2010
    Posts
    70
    Quote Originally Posted by MK27 View Post
    DITTO! One of the worst (if not the worst) mistakes I see here by beginners is writing code without compiling it. It is simply too easy for people to compound mistakes because they don't know they are mistakes, and then they build upon a rotten foundation.

    Bad habit. Don't.



    You should join Game.dev and ask there, that's what it's for. Notice they have forums like here:
    GameDev.Net Discussion Forums
    Thanks for warning me! but, after i write my code on paper, i type it into my compiler and see if i get any errors, you can say its like a test to see if im actually coding correctly without compiler's help with finding the errors and fixing it over and over.

  12. #12
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    Again, this is what you should not do.
    You should type your code and compile regularly. This helps you find your errors quicker and more efficiently.
    Typing the whole thing on paper first will only mean double work and more errors.
    I highly recommend that you rely on the compiler. Type your code into your editor/IDE and compile it when you've finished a part.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  13. #13
    Registered User
    Join Date
    May 2010
    Posts
    70
    Quote Originally Posted by Elysia View Post
    Again, this is what you should not do.
    You should type your code and compile regularly. This helps you find your errors quicker and more efficiently.
    Typing the whole thing on paper first will only mean double work and more errors.
    I highly recommend that you rely on the compiler. Type your code into your editor/IDE and compile it when you've finished a part.
    Oh okay,ill trust your word,thanks for the advice,i took your advice on trying to be ambitous and stuff and using class i wrote this fight simulator, its not very advanced but, it's a start, i made it to reinforce the skills i've learned when i was reading up on classes:

    This is my main.cpp file:
    Code:
    #include <iostream>
    #include "main.h"
    
    
    using namespace std;
    
    int main()
    {
       string x;
       int useratt,oppatt,newhp1,newhp2,rand1,rand2;
    
       Character Goodguy;
    
       Goodguy.Job;
       Goodguy.HP;
       Goodguy.Attack;
       Goodguy.Skill;
       Goodguy.Speed;
       Goodguy.Defence;
    
       Character Badguy;
    
       Badguy.Job;
       Badguy.HP;
       Badguy.Attack;
       Badguy.Skill;
       Badguy.Speed;
       Badguy.Defence;
    
       cout << "What class are you?" << endl;
       cin >> Goodguy.Job;
       cout << "What class is your opponent?" << endl;
       cin >> Badguy.Job;
    
       cout << "It's a " << Goodguy.Job << " VS. " << Badguy.Job << "!" << endl;
       cout << "How attack does your character have?" << endl;
       cin >> Goodguy.Attack;
    
       cout << "How much Defence do you have?" << endl;
       cin >> Goodguy.Defence;
    
       cout << "How much HP do you have?" << endl;
       cin >> Goodguy.HP;
    
       cout << "How much HP does your opponent have?" << endl;
       cin >> Badguy.HP;
    
       cout << "How much Defence does your opponent have?" << endl;
       cin >> Badguy.Defence;
    
       cout << "Do you want to attack?" << endl;
       cin >> x;
    
       rand1 = rand() % 10 + 1;
       rand2 = rand() % 10 + 1;
    
       if(rand1 == rand2)
       {
    
           Goodguy.Attack = Goodguy.critical(Goodguy.Attack);
       }
    
       if(x == "Yes" || x == "yes")
       {
           useratt=Goodguy.attack(Goodguy.Attack,Badguy.HP,Badguy.Defence);
           if(useratt < Badguy.HP)
           {
               newhp2=Badguy.HP-useratt;
               if(rand1 == rand2)
               {
                   cout << "Critical hit" << endl;
                   Goodguy.Attack = Goodguy.critical(Goodguy.Attack);
               }
               cout << "Your opponent lost " << newhp2 << " hp" << endl;
               Badguy.HP=useratt;
           }
           else if(useratt == Badguy.HP)
           {
               cout << "Your opponent still has " << Badguy.HP << " hp" << endl;
               Badguy.HP=Badguy.HP;
           }
       }
       cout << endl;
       cout << "Your opponent's turn to attack!" << endl;
    
       cout << "How much attack does your opponent have?" << endl;
       cin >> Badguy.Attack;
       cout << "Attack: " << Badguy.Attack << endl;
       oppatt=Badguy.attack(Badguy.Attack,Goodguy.HP,Goodguy.Defence);
       if(oppatt < Goodguy.HP)
       {
         newhp2=Goodguy.HP-oppatt;
         cout << "You lost " << newhp2 << " hp" << endl;
         Goodguy.HP=oppatt;
       }
       else if(oppatt == Goodguy.HP)
       {
         cout << "You lost no HP" << endl;
         cout << "You still have " << oppatt << " hp now" << endl;
       }
       cout << endl;
       cout << endl;
    
       cout << "You have has " << Goodguy.HP << " hp now" << endl;
       cout << "Your opponent has " << Badguy.HP << " hp now" << endl;
    
       return 0;
    
    }
    Now this is my header file for main.cpp:

    Code:
    using namespace std;
    
    #ifndef MAIN_H_INCLUDED
    #define MAIN_H_INCLUDED
    
    class Character
    {
      public:
        string Job;
        int Attack;
        int HP;
        int Skill;
        int Speed;
        int Defence;
    
        int attack(int x,int y,int z) // x=user attack,y=opp hp,z=opp def
        {
            int result;
            int diff;
    
            result=(x-z);
            if(result < 0 || result == 0)
            {
               cout << "You did no damage" << endl;
               return y;
            }
            else
            diff=y-result;
    
            return diff;
    
        }
        int critical(int x)
        {
            int result;
            result= x * 3;
            return result;
        }
    };
    
    
    
    
    #endif // MAIN_H_INCLUDED
    What do you think???

  14. #14
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    OK, first:
    Code:
       Goodguy.Job;
       Goodguy.HP;
       Goodguy.Attack;
       Goodguy.Skill;
       Goodguy.Speed;
       Goodguy.Defence;
    
       Badguy.Job;
       Badguy.HP;
       Badguy.Attack;
       Badguy.Skill;
       Badguy.Speed;
       Badguy.Defence;
    What do these do?

    Secondly, I think you are using classes as a collection of variables. This is not right. A class is a blueprint for an object and object is just that--an object. It can be a car, an individual, etc. And when you interact with a car, you tell it accelerate, not mess around with its states and variables.
    So this code
    Code:
    useratt=Goodguy.attack(Goodguy.Attack,Badguy.HP,Badguy.Defence);
    ...is probably not so good.
    A better idea might be:
    Code:
    useratt=Goodguy.attack(Badguy);
    Basically we tell the good guy to attack the bad guy. We don't care HOW it does that. We only care that it's actually done.
    Now this attack function takes care of the gritty details of HOW it's done. This is known as encapsulation and is something we want dearly.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  15. #15
    Registered User
    Join Date
    May 2010
    Posts
    70
    Code:
    Goodguy.Job;
       Goodguy.HP;
       Goodguy.Attack;
       Goodguy.Skill;
       Goodguy.Speed;
       Goodguy.Defence;
    
       Badguy.Job;
       Badguy.HP;
       Badguy.Attack;
       Badguy.Skill;
       Badguy.Speed;
       Badguy.Defence;
    well this is basically the characteristics of your character and the enemy basically, and after since it is a simulator, we tell the user of the program to assign values to these member variables.Now that we have a value for each of the member variables we can use a member function to tell it what to do with these variables for example, we have a function int attack(int x,int y,int z) and in this function we say that we want a return value of the remaining hp after the attack, so we create a result variable and then we use math which is the attack of user - defence of the opponent and then we assign what the answer of this to result.

    After we check if the attack is a negative number(which would mean that the defence of the opponent has to be bigger than the users attack) and if it is a negative number then we want it to print out that you did no damage and return the original hp of the opponent because we did no damage to it.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Machine Learning with Lego Mindstorms
    By DavidP in forum A Brief History of Cprogramming.com
    Replies: 14
    Last Post: 01-30-2009, 02:34 PM
  2. Any tips for learning c?
    By skelectron in forum C Programming
    Replies: 3
    Last Post: 11-20-2005, 11:07 AM
  3. Need Help On a Simple Bank Program
    By oobootsy1 in forum C# Programming
    Replies: 9
    Last Post: 08-08-2005, 10:51 AM
  4. Fun Learning a New Language
    By UnregdRegd in forum A Brief History of Cprogramming.com
    Replies: 16
    Last Post: 09-30-2003, 10:03 PM
  5. API gurus: learning tips?
    By Shadow12345 in forum Game Programming
    Replies: 3
    Last Post: 06-10-2002, 05:32 PM