Thread: increasing variables

  1. #1
    Registered User
    Join Date
    Oct 2002
    Posts
    59

    increasing variables

    Hi all,

    Just a quickie, I want to increase a variable by 3 each time it is ran in a loop;

    I know variable++ increases by one each time, how would i get it to increase by 3??

    Thanks guys


    Boontune

  2. #2

  3. #3
    Registered User
    Join Date
    Oct 2002
    Posts
    59
    Thanks Mate!!

  4. #4
    Hardware Engineer
    Join Date
    Sep 2001
    Posts
    1,398
    boontune - You may already know this... but new programmers can be confused by this:

    MyVariable = MyVariable + 3 ; // Bad in math. OK in programming!

    In programming, this is an ASSIGNMENT (Assigning a new value to MyVariable). it's not an equation!

    For simple operations polymorphic OOP's example is the standard "C++ way" of doing it. But, it is common to see the left-side variable repeated on the right side of the assignment statement.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. basic question about global variables
    By radeberger in forum C++ Programming
    Replies: 0
    Last Post: 04-06-2009, 12:54 AM
  2. Replies: 15
    Last Post: 09-30-2008, 02:12 AM
  3. esbo's data sharing example
    By esbo in forum C Programming
    Replies: 49
    Last Post: 01-08-2008, 11:07 PM
  4. Global Variables
    By Taka in forum C Programming
    Replies: 34
    Last Post: 11-02-2007, 03:25 AM
  5. Replies: 6
    Last Post: 01-02-2004, 01:01 PM