By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
445,778 Members | 1,919 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 445,778 IT Pros & Developers. It's quick & easy.

Strange problem?

P: 6
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.
Expand|Select|Wrap|Line Numbers
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. void separator(int a[ ], int na, int odd[ ], int& no, int even[ ], int& ne)
  5. {
  6.     int i;
  7.     no = ne = 0;
  8.     for (i=0; i<na; i++)
  9.         if (a[i]%2)
  10.             odd[no++] = a[i];
  11.         else
  12.             even[ne++] = a[i];
  13. }
  14.  
  15. int main ()
  16. {
  17.     int na;
  18.     cout << "\nEnter number of components: ";
  19.     cin  >> na;
  20.     int a[100], odd[100], even [100], i;
  21.     cout << "\nEnter components: \n";
  22.     for (i=0; i<na; i++)
  23.     {
  24.         cout << "Component " << i+1 << ": ";
  25.         cin >> a[i];
  26.     }
  27.     cout << "\nInput components: ";
  28.     for (i=0; i<na; i++)
  29.         cout << a[i] << " ";
  30.     cout << endl;
  31.     cout << "Odd components: ";
  32.     for (i=0; i<na; i++)
  33.         cout << odd[i] << " ";
  34.     cout << endl;
  35.     cout << "Even components: ";
  36.     for (i=0; i<na; i++)
  37.         cout << even[i] << " ";
  38.     cout << endl;
  39.  
  40.     return 0;
  41. }
  42.  
  43.  
Thanks again for all the help.
Nov 7 '06 #1
Share this Question
Share on Google+
2 Replies


P: 6
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
Nov 7 '06 #2

10K+
P: 13,264
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.
Nov 7 '06 #3

Post your reply

Sign in to post your reply or Sign up for a free account.