Thread: looping practice

  1. #1
    Registered User
    Join Date
    Sep 2005
    Posts
    196

    looping practice

    before you lauph i did this because im a noob and i didnt know if i could do this.

    basically i want it so the program runs asks you wut number you want to loop and then does it but i got an error.

    Code:
    #include <iostream>
    using namespace std;
    int main()
    {
    int numb;
    
    cout<<"please input the number you would like to loop\n";
    cin>>numb;
    //for the next part where it says <10 i dont really know wut this is but i dont want it.
    for ( int x =  int numb; x <10; x++ ) {
    
        
    cout<< x <<endl;
    
    }
    cin.get();
    }

  2. #2
    System.out.println("");
    Join Date
    Jan 2005
    Posts
    84
    I think you wnat this:

    Code:
    #include <iostream>
    using namespace std;
    int main()
    {
    int numb;
    
    cout<<"please input the number you would like to loop\n";
    cin>>numb;
    //for the next part where it says <10 i dont really know wut this is but i dont want it.
    for ( int x =  0; x <numb; x++ ) 
    {
    
    
    cout<< x <<endl;
    
    }
    cin.get();

  3. #3
    Amazingly beautiful user.
    Join Date
    Jul 2005
    Location
    If you knew I'd have to kill you
    Posts
    254
    Sorry Loctan, was making my reply while you posted yours.

    That code is quite buggy (you are new, some this is understandable). Allow me to show you what is wrong.

    Code:
    for (int x = int numb; x < 10; x++) {
    You want to loop up to the value that the user entered, correct? If so, what you want is.
    Code:
    for (int x = 0; x < numb; x++) {
    Now, you want your "cout <<x << endl;" within braces (within the for loop). In the end do:
    Code:
    #include <iostream>
    using namespace std;
    int main()
    {
      int numb;
      cout << "Please input the number you would like to loop\n";
      cin >> numb;
      
      for (int x = 0; x < numb; x++)
      {
         cout << x << endl;
      }
      cin.get();
      return 0; //This is not necessary, but good common practice.
    }
    Programming Your Mom. http://www.dandongs.com/

  4. #4
    Registered User
    Join Date
    Sep 2005
    Posts
    196
    thank you but now how do i keep the screen up
    never mind i figure out i should use cin.ignore but another problem arises when i say goto 21 itll go to 20
    Last edited by lilhawk2892; 09-21-2005 at 04:47 AM.

  5. #5
    Registered User
    Join Date
    Mar 2003
    Posts
    176
    you shouldn't use goto while loops are much more effective
    If a mime dies in the woods and no one is around to hear it, does it make a sound?

  6. #6
    Registered User
    Join Date
    Jun 2002
    Posts
    230
    Then you would want this
    Code:
    for (int x = 0; x <= numb; x++)
    C++ Rules!!!!
    ------------
    Microsoft Visual Studio .NET Enterprise

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. wierd looping effect after exporting 3ds to .x annimation
    By Anddos in forum Game Programming
    Replies: 3
    Last Post: 01-06-2009, 01:43 PM
  2. Best practice: string manipulation functions
    By samadhi in forum C Programming
    Replies: 4
    Last Post: 09-23-2004, 05:16 PM
  3. looping went berserk
    By miryellis in forum C Programming
    Replies: 7
    Last Post: 09-21-2004, 01:59 PM
  4. Looping questions
    By Peyote in forum C++ Programming
    Replies: 3
    Last Post: 09-15-2003, 11:01 PM
  5. looping and input
    By Kinasz in forum C Programming
    Replies: 2
    Last Post: 03-17-2003, 07:12 AM