Go Back   CodingForums.com > :: Computing & Sciences > Computer Programming

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 05-31-2009, 04:23 PM   PM User | #1
BrickInTheWall
Regular Coder

 
BrickInTheWall's Avatar
 
Join Date: Mar 2009
Location: Munich, Germany
Posts: 139
Thanks: 1
Thanked 13 Times in 13 Posts
BrickInTheWall is on a distinguished road
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
BrickInTheWall is offline   Reply With Quote
Old 05-31-2009, 06:14 PM   PM User | #2
satchel
New Coder

 
Join Date: May 2009
Posts: 88
Thanks: 4
Thanked 4 Times in 4 Posts
satchel is an unknown quantity at this point
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];
}
satchel is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 09:31 AM.


Advertisement
Log in to turn off these ads.