Errors From Functions

So i'm writing a code that will take an input of an array and then separate the negative and non-negative integers into two different arrays. For some reason it's not compiling.
Here are the errors, i've never seen them before

split.cpp:82:60: error: new declaration aint print_array(const string&, int*, int)a
int print_array(const string & prompt, int array[], int num)
^
split.cpp:16:6: error: ambiguates old declaration avoid print_array(const string&, int*, int)a
void print_array(const string & prompt, int array[], int num);
^
heres the code

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
  // File: split.cpp
// Created By: Colton Haas
// Created On: 11/6/2018
// Synopsis: this program prompts the user to input the length of an array and then input that number of intergers in the array. The program then splits the negative numbers from the positive numbers and displaying them in seperate element lists.

#include <iostream>
#include <cmath>
#include <iomanip>

using namespace std;


// function prototypes
void count(int array[], int & numn, int & nump, int SIZE);
void split(int array[], int ap[], int an[], int SIZE, int numn, int nump);
void print_array(const string & prompt, int array[], int num);

int main()
{
  int SIZE(0);
  int numn(0), nump(0);
  int x(0), i(0);
  int num(0);

  cout << "Enter number of elements: ";
  cin >> SIZE;

  int array[SIZE];

  cout << "Enter list: ";
  cin >> x;

  for(i=0; i<SIZE; i++)
    {array[i] = x;
      cin >> x;}

  count(array, numn, nump, SIZE);

  int ap[nump], an[numn];

  split(array, ap, an, SIZE, numn, nump);
  
  print_array("Negative elements:", an, numn);
  print_array("Non-negative elements:", ap, nump);
    

  return(0);
}

// prompts input of the the numbers in the array up to 20
void count(int array[], int & numn, int & nump, int SIZE)
{
  int i(0);

  while (i < SIZE)
    {if (array[i] < 0)
	{numn++;}
      else 
	{nump--;}
      i++;
    }
 }

// outputs the enterd numbers in the array
void split(int array[], int ap[], int an[], int SIZE, int numn, int nump)
{
  int i(0), j(0), k(0);
  for (i=0; i<SIZE; i++)
    {if (array[i] < 0)
	{for (j=0; j<numn; j++)
	    {an[j] = array[i];}
	}
      else
	{for (k=0; k<nump; k++)
	    {ap[k] = array[i];}
	}
    }
 
}

// it finds the max of the numbers in the array
int print_array(const string & prompt, int array[], int num)
{
  cout << prompt << endl;
  int i(0);
  for(i=0; i < num; i++)
    {cout << " " << array[i];
    }
}


Is the problem in the way im defining the function/prototype or in a variable or something? Thanks so much.
I'm sorry, im new to programming and that was kind of like a foreign language to me. Are you saying that the problem is when i'm calling the function to test it in the main? Or is it specifically with the "int num" part of the code?
Your implementation returns 'int' while your prototype returns 'void'. The implementation has to match the prototype. Also, this won't cause a compiler error, but you don't have to name the variables in the prototype.
void print_array(const string&, int[], int); is fine.
Last edited on
I dont know how i missed that, thanks so much! i feel so silly.
Topic archived. No new replies allowed.