Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    Regular Coder BrickInTheWall's Avatar
    Join Date
    Mar 2009
    Location
    Munich, Germany
    Posts
    139
    Thanks
    1
    Thanked 13 Times in 13 Posts

    Need help with variable names...

    Hi,
    I need to know how to do the following in C++:
    Lets say I hat like 10 variables which all have similar names like this:
    number0, number1, number2, number3.....number9

    I want assign values to all of these variables at a certain time in a program but don't feel like typing all of the names and would rather use a for loop:
    for( int i = 0; i < 10; i++ )
    {
    "number + i" = i;
    }

    something like that...I know how to do this in actionscript, but it doesn't seem to be working here...any tips on how I can do this?
    Thanks

  • #2
    New Coder
    Join Date
    May 2009
    Posts
    88
    Thanks
    4
    Thanked 4 Times in 4 Posts
    I'm not sure it's possible, at least, I haven't heard of it, or been able to find a way... You could try using an array instead like this:
    Code:
    int number[10];
    for( int i = 0; i < 10; i++ ) {
        number[i] = i;
        cout<<number[i];
    }


  •  

    Posting Permissions

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