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.
Thanks again for all the help.
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; }
Comment