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
Results 1 to 2 of 2

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

  1. #1
    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. #2
    Join Date
    Dec 2012
    Location
    England
    Posts
    2,557

    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 '#'.
    All advice is offered in good faith only. You are ultimately responsible for effects of your programs and the integrity of the machines they run on.

Tags for this Thread

Posting Permissions

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


Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center