473,486 Members | 1,950 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Strange problem?

6 New Member
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
2 1062
ipazman420
6 New Member
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
r035198x
13,262 MVP
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

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

Similar topics

5
2291
by: Rob Ristroph | last post by:
Hi, It's pretty unhelpful to post "I have a huge piece of code that crashes in strange places, what's the problem?" but that's basically my problem and I really am at my wit's end. The piece...
2
1946
by: Paul Drummond | last post by:
Hi all, I am developing software for Linux Redhat9 and I have noticed some very strange behaviour when throwing exceptions within a shared library. All our exceptions are derived from...
25
3695
by: Neil Ginsberg | last post by:
I have a strange situation with my Access 2000 database. I have code in the database which has worked fine for years, and now all of a sudden doesn't work fine on one or two of my client's...
2
1763
by: TB | last post by:
I am seeing a very strange problem as follows... I have a loop where a fair amount of processing is going on and near the top of the loop I access a class that has only static helper functions...
1
3751
by: Sam Kong | last post by:
Hello! Recently I had a strange problem with Visual C# 2005 beta 1. When I ran(F5 key) a program, <#if DEBUG> statement was not working. It ran as RELEASE mode. So I had to manually define...
8
6667
by: Spam Trap | last post by:
I am getting strange resizing problems when using an inherited form. Controls are moving themselves seemingly randomly, but reproducibly. "frmBase" is my base class (a windows form), and...
11
2565
by: Martin Joergensen | last post by:
Hi, I've encountered a really, *really*, REALLY strange error :-) I have a for-loop and after 8 runs I get strange results...... I mean: A really strange result.... I'm calculating...
12
2245
by: StephQ | last post by:
I have a class Bounds with two constructors: class Bounds { private: list<SegmentupperLinearSpline; // Upper bound. list<SegmentlowerLinearSpline; // Lower bound. ....
8
5268
by: Dox33 | last post by:
I ran into a very strange behaviour of raw_input(). I hope somebody can tell me how to fix this. (Or is this a problem in the python source?) I will explain the problem by using 3 examples....
5
2404
by: ioni | last post by:
Good day, fellows! I have a strange problem – at my site there is a flash strip, that loads data dynamically. It works fine (grabs data from the remote server and presents it), however in IE7...
0
7094
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7173
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
5427
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
4863
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4559
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3066
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3070
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
598
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
259
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.