[Linker error] undefined reference to `binarySearch(int*, int, int)'

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
#include <iostream>
#include <fstream>
using namespace std;
void bubbleSort (int arrayone[], double arraytwo[],int x){
  	bool swapped = true;
  	int j = 0,temp;
  	double tmp,tmpone;
  	while (swapped) {
        	swapped = false;
        	j++;
        	for (int i = 0; i < x - j; i++) {
              	if (arrayone[i] > arrayone[i + 1]) {
                    	temp = arrayone[i];
                    	arrayone[i] = arrayone[i + 1];
                        arrayone[i + 1] = temp;
                    	swapped = true;}
              	if (arraytwo[i] > arraytwo[i + 1]) {
                    	tmp = arraytwo[i];
                        arraytwo[i] = arraytwo[i + 1];
                        arraytwo[i + 1] = tmp;
                    	swapped = true;}
                   	 

        	}

  	}
   }
int binarySearch(int arrayone[],int first,int last,double key){
   while (first <= last) {
       int mid = (first + last) / 2;  // compute mid point.
       if (key > arrayone[mid]) 
           first = mid + 1;  // repeat search in top half.
       else if (key < arrayone[mid]) 
           last = mid - 1; // repeat search in bottom half.
       else
           return mid;     // found it. return position /////
   }
   return -(first + 1);
}

int processAccounts(char *, char *, double &, double &){
int arrayone[24];
ifstream inputFile;
double arraytwo[24],y=0;
double totalCharges,pastDueCharges;
int number,x=0,z,k=0,t=0;
char temp;
double pastDue[24];

inputFile.open("account balance.txt");
if (inputFile.is_open()){
while (inputFile>>number){
      inputFile>>arrayone[x];
      inputFile>>temp;
      inputFile>>arraytwo[x];
      totalCharges=arraytwo[x]+totalCharges;
      x++;
      }}
else
    cout<<"Couldn't read the file with balance.";
inputFile.close();
bubbleSort(arrayone,arraytwo,x);
inputFile.open("past due accounts.txt");
if (inputFile.is_open()){
while (inputFile>>number){
      inputFile>>pastDue[t];
      y=pastDue[t];
      z=binarySearch(arrayone,k,x,y);
      pastDueCharges=pastDueCharges+arraytwo[z];
      t++;
      }}
else
    cout<<"Couldn't read the file with past due accounts.";
inputFile.close();
cout<<"\nTotal Charges: $"<<totalCharges;
cout<<"\nPast Due Charges: $"<<pastDueCharges;
}


i have no idea wat causes that error, but maybe its the .obj file that i had to add to linker command line or something

also how can i read in stuff separated by commas in a file, because i have to
read in a number to one array, then ignore the name,then read in a number to another array , which i try to do here:
1
2
3
inputFile>>arrayone[x];
      inputFile>>temp;
      inputFile>>arraytwo[x];

the "account balance.txt" file contains account number(numbers),name,account balance(numbers)
teacher said we can skip the name, and i have no idea how to actually read in the values that are seperated by commas, nothing about that in my book
Topic archived. No new replies allowed.