Strange problem?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • ipazman420
    New Member
    • Nov 2006
    • 6

    Strange problem?

    Okay, so I'm trying to make a program that takes one array and splits the odd components from the even components, and I'm supposed to show what comes out. The thing is, my program doesn't separate it for some reason. I'm trying to figure out where the problem could be in my coding... Here's what I have.
    Code:
    #include <iostream>
    using namespace std;
    
    void separator(int a[ ], int na, int odd[ ], int& no, int even[ ], int& ne)
    {
    	int i;
    	no = ne = 0;
    	for (i=0; i<na; i++)
    		if (a[i]%2)
    			odd[no++] = a[i];
    		else
    			even[ne++] = a[i];
    }
    
    int main ()
    {
    	int na;
    	cout << "\nEnter number of components: ";
    	cin  >> na;
    	int a[100], odd[100], even [100], i;
    	cout << "\nEnter components: \n";
    	for (i=0; i<na; i++)
    	{
    		cout << "Component " << i+1 << ": ";
    		cin >> a[i];
    	}
    	cout << "\nInput components: ";
    	for (i=0; i<na; i++)
    		cout << a[i] << " ";
    	cout << endl;
    	cout << "Odd components: ";
    	for (i=0; i<na; i++)
    		cout << odd[i] << " ";
    	cout << endl;
    	cout << "Even components: ";
    	for (i=0; i<na; i++)
    		cout << even[i] << " ";
    	cout << endl;
    
    	return 0;
    }
    Thanks again for all the help.
  • ipazman420
    New Member
    • Nov 2006
    • 6

    #2
    Woah, I just found what my problem was; I didn't put the function into the main program. Guess I just answered my own question. =P

    Comment

    • r035198x
      MVP
      • Sep 2006
      • 13225

      #3
      Originally posted by ipazman420
      Woah, I just found what my problem was; I didn't put the function into the main program. Guess I just answered my own question. =P
      Good for you.

      Comment

      Working...