Storing calculated values in an array

I have an assignment in which I must manipulate an array in several different ways. I am stuck on trying to change the values stored in the array so that they can then be printed. I need to change the values so that the difference between the original value and the average of all the values is stored in the array so that it can be printed. The entirety of my code so far is below:

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
#include <iostream>
#include <iomanip>

using namespace std;

void getlist(int [], int &); // user inputs list
void printlist(const int [], int); // prints the array
float meanAverage(const int [], int); // finds the average of the array
// finds the differences between the items in the array
void findDifferences(float, const int [], int);

const int ARRAYSIZE = 25; // array size
int j, list[ARRAYSIZE]; // general array
int diff[ARRAYSIZE]; // array for finding differences

int main()
{
	int num_items;
	float average;
	
	getlist(list, num_items); //user inputs array values
	
	printlist(list, num_items); //prints users array
	
	average = meanAverage(list, num_items); //calculates the average of the users array
	cout << "The average of your array is "
		 << average << endl << endl;
		 
	findDifferences(average, list, num_items);
	
	printlist(diff, num_items);
	
	system("pause");
	return 0;
}

void getlist(int list[], int & num_items)
{
    cout << "Please enter the number of array values: ";
    cin >> num_items;
    
    cout << "Enter the first array value: ";
    cin >> list[j];

    for(int i = 1; i < num_items; i++)
        {
             cout << "Enter the next array value: ";
             cin >> list[j];
        }
}

void printlist(const int list[], int num_items)
{
	for(int i = 0; i < num_items; i++)
        cout << setiosflags(ios::right) << setw(4)
			 << "[" << i << "]"
             << setw(5) << list[j] << endl;
}

float meanAverage(const int list[], int num_items)
{
	float total = 0;
	
    for(int i = 0; i < num_items; i++)
        total = total + list[j];
    return total / num_items;
}

void findDifferences(int average, const int list[], int num_items)
{
	for(int i = 0; i < num_items; i++)
		diff[j] = list[j] - average;
}


I get this error message when I try to compile and run the program:

Array__Manip.cpp:(.text+0xad): undefined reference to `findDifferences(float, int const*, int)'

Please help me figure out what it is that I'm doing wrong because I can't seem to figure it out. Thanks in advance for the help.
The forward declarations signature of findDifference() doesn't match those of the function definition.
Can you please what you mean by that?
Last edited on

Line 10: void findDifferences(float, const int [], int)

and

Line 69: void findDifferences(int, const int[], int)

are signatures of two different functions with the same name. The first one will be called if the first actual parameter is of type float while the second one expects an int as its first argument.

Line 29 uses a float as first actual parameter and so the linker looks for a function definition of the appropriate signature - and doesn't find one.

(See http://www.cplusplus.com/doc/tutorial/functions2/ for details)
Topic archived. No new replies allowed.