loops

This is a discussion on loops within the C++ Programming forums, part of the General Programming Boards category; I have just started learning c++ for like a mont on and off, but i have a problem well its ...

  1. #1
    Registered User
    Join Date
    Oct 2005
    Posts
    4

    Question loops

    I have just started learning c++ for like a mont on and off, but i have a problem well its more like y is this doing wat its doing... i though since you can make a program count from 0 to 10 or watever and i can make it count backwards from 10 then i should be able to make it count by 5's..

    well this is the only way i could do this

    Code:
    #include <iostream>
    
    using namespace std;
    
    int main() {
    
         for( int x = 0; x < 11; x++ ) {
                cout<<x * 5 <<endl;
         }
         cin.get();
    }

    now im fine with that but y do i have to use 11 instead of 50. is it because that is tell the program how many times to loop it or wat??

  2. #2
    ^ Read Backwards^
    Join Date
    Sep 2005
    Location
    Earth
    Posts
    282
    now im fine with that but y do i have to use 11 instead of 50. is it because that is tell the program how many times to loop it or wat??
    You do not have to use 11, you can use any number you want.

    I am not sure what you are asking?

    To make it count by 5's instead of "x++" you could just do "x + 5"
    "x++" is the same thing as "x + 1".

  3. #3
    Registered User
    Join Date
    Oct 2005
    Posts
    4
    To make it count by 5's instead of "x++" you could just do "x + 5"
    see i tried using x + 5 instead of x++, but the program just ran 0 like a million times..

  4. #4
    semi-colon generator ChaosEngine's Avatar
    Join Date
    Sep 2005
    Location
    Chch, NZ
    Posts
    597
    Quote Originally Posted by derangedrobot
    see i tried using x + 5 instead of x++, but the program just ran 0 like a million times..
    try x += 5
    x + 5 does nothing to x.
    x += 5 is the same as x = x + 5

  5. #5
    Registered User
    Join Date
    Oct 2005
    Posts
    4
    lol some how i knew it was going to be somthing as simple as that, ty that was going to bug me for ever.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Too many loops D:
    By F5 Tornado in forum C++ Programming
    Replies: 6
    Last Post: 12-03-2007, 12:18 AM
  2. For/Next Loops...adding 10 numbers...
    By IanelarAzure in forum C++ Programming
    Replies: 5
    Last Post: 09-12-2002, 12:02 PM
  3. recoursion or loops?
    By Mecnels in forum C++ Programming
    Replies: 2
    Last Post: 01-14-2002, 11:09 AM
  4. help with arrays and loops
    By jdiazj1 in forum C Programming
    Replies: 4
    Last Post: 11-24-2001, 03:28 PM
  5. for loops - newbie q's
    By Narciss in forum C Programming
    Replies: 8
    Last Post: 09-26-2001, 02:44 AM

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