• Lucid Dreaming - Dream Views




    Results 1 to 25 of 165

    Hybrid View

    1. #1
      Gentlemen. Ladies. slayer's Avatar
      Join Date
      Mar 2007
      Gender
      Location
      Right here... Reputation: 9999
      Posts
      4,902
      Likes
      473
      DJ Entries
      4
      int main()
      {
      int a, b;
      int result;

      a = 5;
      b = 4;
      a = a + 1;
      result = a - b;

      cout <<result<<endl;
      }

      It might look really confusing at first, but when you actually sit down and read it slowly, it's pretty easy to understand.

      In the code I provided, I'm saying that a = 5 and b = 2, then I'm taking a and adding 1 to it, then taking the new answer of a and subtracting it from b which would give me 2.

      I just started learning yesterday :3

      I'm using code::blocks for my C++ writing along with the www.cplusplus.com website.

    2. #2
      .. / .- –– / .- .-. guitarboy's Avatar
      Join Date
      Sep 2008
      LD Count
      Over 9000
      Gender
      Location
      Homeward Bound
      Posts
      1,571
      Likes
      49
      Should I learn C or C++ first?

    3. #3
      Gentlemen. Ladies. slayer's Avatar
      Join Date
      Mar 2007
      Gender
      Location
      Right here... Reputation: 9999
      Posts
      4,902
      Likes
      473
      DJ Entries
      4
      I'm learning C++ to learn how to make my own game engine. I don't really know anything about C.

    4. #4
      khh
      khh is offline
      Remember Achievements:
      1000 Hall Points Veteran First Class
      khh's Avatar
      Join Date
      Jun 2009
      Gender
      Location
      Norway
      Posts
      2,482
      Likes
      1309
      Well, it depends on what you want to do with it. C++ is better for large projects, while C is best if you're writing time-critical applications. C would also be the logical choice if you want to make other things than computer programs, like if you want to program other integrated chips.
      Many hold that you should always learn C first and then move on to C++, as C++ almost is a superset of C, but either way knowing one will help you with the other.
      April Ryan is my friend,
      Every sorrow she can mend.
      When i visit her dark realm,
      Does it simply overwhelm.

    5. #5
      FBI agent Ynot's Avatar
      Join Date
      Oct 2005
      Gender
      Location
      Southend, Essex
      Posts
      4,337
      Likes
      14
      Quote Originally Posted by khh View Post
      Many hold that you should always learn C first and then move on to C++
      I disagree with that

      There's certain things that are the "right way" in C, but the "wrong way" in C++ (and vice versa)
      Arrays being the biggy

      You may fall into the trap of using wrong methodologies in either language
      (\_ _/)
      (='.'=)
      (")_(")

    6. #6
      Banned
      Join Date
      Apr 2007
      Location
      Out Chasing Rabbits
      Posts
      15,193
      Likes
      935
      Quote Originally Posted by Ynot View Post
      There's certain things that are the "right way" in C, but the "wrong way" in C++ (and vice versa)
      Arrays being the biggy
      Arrays are exactly the same in C and C++.

      He's right about the right and wrong ways being different in C and C++

      Critical section in C
      Code:
      void CriticalMethod(void){
         pthread_mutex_lock(somelock);
         //some critical stuff
         if (boolean){
            pthread_mutex_unlock(somelock);  //have to unlock in every exit path
            return;
         }
         //more critical stuff
         pthread_mutex_unlock(somelock);
      }
      Critical section in C++
      Code:
      //Autolock.h
      struct AutoLock{
         public:
            AutoLock(pthread_mutex_t * lock){
               pthread_mutex_lock(lock);
               mylock = lock;
            }
            ~AutoLock(void){
               pthread_mutex_unlock(mylock);
            }
         private:
            pthread_mutex_t mylock;
      }
      Code:
      void CriticalMethod(void){
         AutoLock lock(somelock);  //will automatically unlock when it returns
         //some critical stuff
         if (boolean){
            return;
         }
         //More critical stuff
      }

      ***********************


      What exactly would you like to know guitarboy, honoured you came to me

      I learned C first, then taught myself C++. I would recommend just learning C++, most programming is done in C++, and it's a lot easier. It's also a good thing to understand object oriented programming.

      Here's some things to understand, in order
      Primitive types: int, long, float, char
      Scope
      methods and functions
      pass-by-reference vs pass-by-value
      const
      Pointers
      Objects (classes and structs)
      Constructors and destructors

      Feel free to IM me about anything
      Last edited by ninja9578; 01-08-2010 at 01:00 AM.

    7. #7
      FBI agent Ynot's Avatar
      Join Date
      Oct 2005
      Gender
      Location
      Southend, Essex
      Posts
      4,337
      Likes
      14
      Quote Originally Posted by ninja9578 View Post
      Arrays are exactly the same in C and C++.
      I know they are the same
      but they're hailed in C, and frowned upon in C++

      From the man himself
      http://www2.research.att.com/~bs/bs_faq2.html#arrays
      (\_ _/)
      (='.'=)
      (")_(")

    8. #8
      Member Achievements:
      1 year registered Veteran First Class 5000 Hall Points

      Join Date
      Sep 2004
      Gender
      Location
      Seattle, WA
      Posts
      2,503
      Likes
      217
      Quote Originally Posted by slayer View Post
      I'm learning C++ to learn how to make my own game engine. I don't really know anything about C.
      If you're just getting started with C++, I recommend a few smaller (like, MUCH smaller) projects first.

    9. #9
      FBI agent Ynot's Avatar
      Join Date
      Oct 2005
      Gender
      Location
      Southend, Essex
      Posts
      4,337
      Likes
      14
      Quote Originally Posted by Replicon View Post
      If you're just getting started with C++, I recommend a few smaller (like, MUCH smaller) projects first.
      Indeed,
      first learn the language, then do something small and easy to get the hang of things
      Quote Originally Posted by Ynot View Post
      hangman is always a good first game

      pick a random word from file of possible words
      let the user guess letters
      print letters found, and underscores for not found
      keep a count of num guesses

      You've just started on your journey as a bridge-builder
      Your ultimate aim is this
      http://secretperson.files.wordpress....n-bridge-l.jpg
      but you've got to start off building a few of these first
      http://www.freeimageslive.co.uk/file...46.preview.jpg
      Last edited by Ynot; 01-09-2010 at 03:35 AM.
      (\_ _/)
      (='.'=)
      (")_(")

    10. #10
      Banned
      Join Date
      Apr 2007
      Location
      Out Chasing Rabbits
      Posts
      15,193
      Likes
      935
      I agree, you saw my design right? Mario is a fairly simple game, yet it's quite a lot of classes and functionality. I could probably knock it out in a day, but I'm very experienced.

    11. #11
      Gentlemen. Ladies. slayer's Avatar
      Join Date
      Mar 2007
      Gender
      Location
      Right here... Reputation: 9999
      Posts
      4,902
      Likes
      473
      DJ Entries
      4
      I guess I made my first game!

      Simple if/else statement set up.

      Code:
      #include <iostream>
      using namespace std;
      
      int main()
      {
          int a;
      
          cout << "Please enter the number 3: ";
          cin >> a;
          if ( a == 3)
          {
              cout << "You have entered the right number!";
          }
          else
          {
              cout << "You lost the game.";
          }
          return 0;
      }
      If you enter the number 3, you win! But if you don't, then you lose!

      How would I set it up so it repeats the first line of code?

      I want to set it up so that if the player enters the wrong number, then it goes to repeat the "Please enter the number 3" part. Or, if they get it wrong, then it asks for the player "Do you want to play again? Y/N" and if they enter Y then the whole thing repeats itself, or if they enter N, then the game exits.

    12. #12
      FBI agent Ynot's Avatar
      Join Date
      Oct 2005
      Gender
      Location
      Southend, Essex
      Posts
      4,337
      Likes
      14
      either, really
      they're 80% the same
      (C++ started out as an extension to C)

      depends if you prefer procedural or object orientated programming
      (\_ _/)
      (='.'=)
      (")_(")

    Bookmarks

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •