Help with c++ noob stuff please

This is a discussion on Help with c++ noob stuff please within the C++ Programming forums, part of the General Programming Boards category; Code: #include <iostream> using namespace std; // So the program can see cout and endl int main() { // The ...

  1. #1
    C++ and openGL Raeliean's Avatar
    Join Date
    Jul 2005
    Posts
    28

    Help with c++ noob stuff please

    Code:
     
    #include <iostream>
    
    using namespace std; // So the program can see cout and endl
    
    int main()
    {
      // The loop goes while x < 10, and x increases by one every loop
      for ( int x = 0; x < 10; x++ ) {
        // Keep in mind that the loop condition checks 
        //  the conditional statement before it loops again.
        //  consequently, when x equals 10 the loop breaks.
        // x is updated before the condition is checked.    
        cout<< x <<endl;
      }
      cin.get();
    }
    It adds one everytime until it ges to 10, how can I make it add more like 2 at a time or 3 at a time?

  2. #2
    Registered User
    Join Date
    Jul 2005
    Posts
    2
    Instead of x++, put in

    x+=2, x+=3, etc..

    those are shortcuts for "x = x + 2" and "x = x + 3"

  3. #3
    Registered User
    Join Date
    Jun 2004
    Posts
    722
    that code includes a for cycle
    it has the syntax
    Code:
    for(initial statement;condition for looping;expressions evaluated at end of any cycle)
    {
        code to be executed
    }
    In the 'expressions evaluated at end of any cycle' you have x++.
    x is a integer. ++ is a operator that increments the value of the variable.
    writing x++ increments x.
    it's the same as x = x+1; or x +=1;
    knowing this, try to change that expression to add 2 or 3 to x;
    Last edited by xErath; 07-03-2005 at 07:13 PM.

  4. #4
    C++ and openGL Raeliean's Avatar
    Join Date
    Jul 2005
    Posts
    28
    Thanks guys, I understand it now.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. quick noob question
    By thanatos1 in forum C# Programming
    Replies: 2
    Last Post: 06-17-2009, 09:28 PM
  2. noob needs help!!!!:(
    By tykenfitz in forum C Programming
    Replies: 1
    Last Post: 07-10-2005, 09:49 AM
  3. Tab key stuff. C+WinAPI is killing me. Please help.
    By Templario in forum Windows Programming
    Replies: 5
    Last Post: 11-21-2002, 03:35 PM
  4. arguments, directories and stuff...
    By Unregistered in forum C Programming
    Replies: 3
    Last Post: 06-26-2002, 06:46 PM
  5. Your stuff
    By smog890 in forum C Programming
    Replies: 6
    Last Post: 06-14-2002, 12:50 AM

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