No matching function for call to?

For whatever reason, I get an error meassage about lines 53-57 saying there is no matching function to call to. Yet the header and the prototype are correct (I think anyways).

Any help is much appreciated

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
#include <iostream>
#include <string>
#include <fstream>
#define N 10

using namespace std;

  class cust{
        public:
            string first;
            string last;
            int UPerchased;
            string state;
            double SHistory[10];
    };

void printcust(cust[],int);
void sortsales(double [],int);
void sortname(cust[],int);

int main(){
    ifstream namefile, statefile, salehistoryfile, unitsfile;
    namefile.open("/Users/Soul/Documents/School/CISC/Assignment10/Assignment10/namefile.txt");
    statefile.open("/Users/Soul/Documents/School/CISC/Assignment10/Assignment10/statefile.txt");
    salehistoryfile.open("/Users/Soul/Documents/School/CISC/Assignment10/Assignment10/salehistoryfile.txt");
    unitsfile.open("/Users/Soul/Documents/School/CISC/Assignment10/Assignment10/namefile.txt");

    class cust{
        public:
            string first;
            string last;
            int UPerchased;
            string state;
            double SHistory[10];
    };

    cust cust[N];
    for(int a = 0; a<N; a++){
        namefile >> cust[a].first;
        namefile >> cust[a].last;
    }
     for(int b = 0; b<N; b++){
        statefile >> cust[b].state;
    }
     for(int c = 0; c<N; c++){
        unitsfile >> cust[c].UPerchased;
    }
     for(int d = 0; d<N; d++){
        salehistoryfile >> cust[d].SHistory[0];
        salehistoryfile >> cust[d].SHistory[1];
        salehistoryfile >> cust[d].SHistory[2];
    }
    printcust(cust,N);
    sortname(cust,N);
    printcust(cust,N);
    sortsales(cust,N);
    printcust(cust,N);
    return 0;
}

void sortname(cust name[],int nelts){
string temp;
for(int pass = 0; pass<nelts-1;pass++)
    for(int cand = 1;cand<nelts; cand++ )
        if(name[pass].last>name[cand].last){
            temp = name[pass].last;
            name[pass].last = name[cand].last;
            name[cand].last = temp;
        }
return;
}

void sortsales(cust name[],int nelts){
double temp;
for(int pass = 0; pass<nelts-1;pass++)
    for(int cand = 1;cand<nelts; cand++ )
        if((name[pass].SHistory[1]+name[pass].SHistory[2]+name[pass].SHistory[0])>(name[cand].SHistory[1]+name[cand].SHistory[2]+name[cand].SHistory[0])){
            temp = name[pass].SHistory[0];
            name[pass].SHistory[0] = name[cand].SHistory[0];
            name[cand].SHistory[0] = temp;
        }
return;
}

void printcust(cust custo[],int nelts){
for(int w = 0; 0<nelts; w++)
cout << custo[w].first << " " << custo[w].last << " " << custo[w].state << " " << custo[w].SHistory[0] << " " << custo[w].SHistory[1] << " " << custo[w].SHistory[2] << " " << custo[w].UPerchased << endl;
return;
}
You don't need to re-declare the class within main. Just leave the class definition outside of main and take out lines 28-35.

There's a discrepancy in this function. The prototype says it takes an array of doubles, but the definition says it takes an array of custs.

1
2
void sortsales(double [],int);
void sortsales(cust name[],int nelts){
I did the changes, but for some reason my program's output is:

Last login: Wed Dec 10 18:28:51 on ttys000
/Applications/CodeBlocks.app/Contents/MacOS/cb_console_runner DYLD_LIBRARY_PATH=$DYLD_LIBRARY_PATH:. /Users/Soul/Documents/School/CISC/Assignment10/bin/Debug/Assignment10
Christians-MacBook-Pro:~ Soul$ /Applications/CodeBlocks.app/Contents/MacOS/cb_console_runner DYLD_LIBRARY_PATH=$DYLD_LIBRARY_PATH:. /Users/Soul/Documents/School/CISC/Assignment10/bin/Debug/Assignment10
name
6.95326e-310 6.95324e-310 6.95324e-310 -1972146176
6.95324e-310 6.95324e-310 6.95324e-310 1873970752
6.95321e-310 6.95321e-310 6.95321e-310 1873970496
6.95321e-310 6.95326e-310 4.94066e-324 512
3.54097e-320 6.91692e-323 6.95324e-310 406703
6.95324e-310 5.16023e-311 6.95321e-310 6
6.95327e-310 6.95324e-310 6.95327e-310 2
6.95321e-310 6.95324e-310 6.95321e-310 -1780561400
1.39612e-309 8.82401e-321 8.85366e-321 1
6.95321e-310 6.95324e-310 6.95324e-310 3
@dS??B\
?C\
p??v?b:?l C\
p??v?b:? 0 6.93919e-310 0 0
0 0 0 0
0 0 0 0
??v? 0 0 2.122e-314 0
0 6.95324e-310 0 0
0 0 0 0
1.97626e-323 6.95321e-310 6.95324e-310 207373040
B\
?C\
p??v?B:? 6.95324e-310 0 0 0
0 0 0 0
0 0 0 0
B\
hEdS?p??v? 0 0 0 1991703664
0 0 0 0
0 0 0 0
0 3.23796e-319 2.22445e-314 0
2.122e-314 0 0 0
IdS?XEdS? EdS?GdS?GdS?hEdSC\
XEdS? C\
6.95321e-310 6.95321e-310 8.39912e-323 1399080296
DdS?HKdS??[
?@dS?pBdS?pBdS??@dSC\
?@dS??@dS?pBdS?c @dS?pBdS?pBdS??@dSC\
?@dS??@dS?pBdS?c?LF?O8KdS?ɥs??ɥs?? C\
6.95321e-310 1.04049e-202 6.95321e-310 1399079128

Process returned -1 (0xFFFFFFFF) execution time : 0.220 s
Press ENTER to continue.

Are you sure the files are opening? You can use the is_open() function to verify.

http://www.cplusplus.com/reference/fstream/ifstream/is_open/
This files are opened
I'm not sure how the data is formatted in these separate files. I might try the while loop strategy in your other thread.

http://www.cplusplus.com/forum/beginner/150674/#msg786000
Topic archived. No new replies allowed.