How to write an array into 3 diff. arrays? odd, even, negative
 CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com

# Thread: How to write an array into 3 diff. arrays? odd, even, negative

1. Junior Member
Join Date
Jan 2014
Posts
12

## How to write an array into 3 diff. arrays? odd, even, negative

question : Place the even lucky numbers in an array called evenList, the odd lucky numbers in an array called oddList, and the negative lucky numbers in an array called negList.

//So in main main i passed the array as parameter and the size;

void lucknumberlist(int favnum[], int size)
{
int even = 0, odd = 0, neg = 0;
int evenArray[even];
int oddArray[odd];
int negArray[neg];

if(favnum[even] % 2 == 0)
{
evenArray[even] = favnum[even];
even++ ;
}
else if(favnum[odd] % 2 == 1)
{
oddArray[odd] = favnum[odd];
odd++;
}
else
{
negArray[neg] = favnum[neg];
neg++;
}

//tried printing to check if worked.. but no luck!!

for (int i = 0; i < size; i++)
{
cout << oddArray[i] << " ";
}
}

2. ## Re: How to write an array into 3 diff. arrays? odd, even, negative

Code:
```int even = 0, odd = 0, neg = 0;
int evenArray[even];```
In standard c++, this is not a valid way to define an array as even is a variable and not a const. Even if this way of defining an array was legal, you would have an array of 0 elements as even is 0.

You would be better off using vectors to store the even, odd and negative numbers.

Also when posting code, please use code tags. Go Advanced, select the code and click '#'.

#### Posting Permissions

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