Hi,
I've been toiling over this problem for about two weeks, and I'll be the first to admit I have no idea what I'm doing. I'm in a beginner C programming class that I only needed to take for graduating, so I'm not a programmer and I don't want to be one.
That said, I don't mind the challenge, it's just that this is getting frustrating.
So the problem is this:
Define an array w/ 20 integer values, fill array with numbers (input or hard-coded)
Write function called split() to read array and put all + #s in "positive" array and - #s into "negative" array
Call a function to display values in both positive & negative arrays
Extend program to sort positive & negative arrays in ascending order before they are displayed
I created the major array with 20 values and put the numbers in there. I kind of wrote the split() function except I probably did everything wrong. What I did was piece together different parts from the section on Arrays in my textbook as far as I understood them, and it's not working right.
Here's my code:
Code:
#include <stdio.h>
#define MAXELS 20
int split(int [], int, int);
int main()
{
int vals[MAXELS] = {12, 34, -43, 4, -34, 0, 11, 23, 46, 33, -67, 90, 100, 13, -16, 29, 17, 18, 19, 20} ;
int value;
value = split(vals, MAXELS, 0);
return 0;
}
int split(int num[], int pos, int neg)
{
int x, y;
for (x = 0; x < MAXELS; x++)
if (num[x] >= 0)
num[x] = num[pos];
for (y = 0; y < MAXELS; y++)
if (num[y] <= 0)
num[y] = num[neg];
printf("Positive numbers: \n", x);
printf("Negative numbers: ", y);
return (x, y);
}
It compiles but the Positive Numbers: and Negative Numbers: print out nothing.
I most likely am missing a concept (or several) here, but I have my textbook open to the Arrays chapter and I'm willing to learn if anyone is kind enough to help me out. I'm kind of embarrassed to throw my code out there because it probably makes NO sense! Thanks in advance though!