No matching function for call to?

Every time I try to compile this, I get the error message, "error: no matching function for call to" on lines 18, 45, and 46. Basically every time I try to call on the function sales and printStock.
I don't know what the message means or why I get it.
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
  #include <iostream>
#include <fstream>
#define N 10
using namespace std;

void printStock (float [], int);
float sales (float [], int);

int main()
{
    ifstream myfile;
    myfile.open("/Users/Soul/Documents/School/CISC/Assignment6/file.rtf");
    if (myfile.is_open())
        cout << "It works" << endl;
    float inv[N], cmt;
    int acct, type;

    printStock(inv[N],N);

    for(int n = 0; n > N; n++)
        inv[n] = 0;
     myfile>>type;
     myfile>>acct;
     myfile>>cmt;

    while(myfile){
        if (type == 1){
            inv[acct] += cmt;
            cout << "Deposit: " << cmt;
        }
            else;
        if (type == 2){
            inv[acct] -= cmt;
            cout << "Withdrawal: " << cmt;
        }
            else;
        if (inv[acct] < cmt)
                cout << "ERROR: Overdraw" << endl;
                else;
        if (type != 1 && type != 2)
            cout << "ERROR: Invalid Transation number" << endl;
    myfile >> type >> acct >> cmt;
    }
    myfile.close();
    printStock(inv[N],N);
    cout << "Total Income" << sales(inv[N],N) endl;
    return 0;
    }


void printStock(float inv[], int nelts){
for (int n = 0; n>nelts; n++)
    cout << n << inv[n];
return;
}

float sales(float inv[], int nelts){
float sum = 0;
for (int n = 0; n>nelts; n++)
    sum += inv[n];
    return sum;
}
when you call a function passing an array, all you need to pass is the name of the array printStock( inv, N ); what you're doing with printStock(inv[N],N); is only trying to pass the Nth element of the array.
Last edited on
@ProgrammerSoul

When you call the function, you just send the name and not the brackets. So, these
printStock(inv[N],N); should look like printStock(inv,N);


And your for loops are wrong
1
2
3
4
5
void printStock(float inv[], int nelts){
for (int n = 0; n>nelts; n++) // Use < not >. Same for your float sales() function.
    cout << n << inv[n];
return;
}
Last edited on
I fixed the function class, but now the program doesn't print anything. I tested to see if its the file, but the program claims the file works.
@ProgrammerSoul

Post your new code and an example of the input file. Maybe we then see where things aren't working, more easily.
For some reason, it doesn't work
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
#include <iostream>
#include <fstream>
#define N 10
using namespace std;

void printStock (float [], int);
float sales (float [], int);

int main()
{
    ifstream myfile;
    myfile.open("/Users/Soul/Documents/School/CISC/Assignment6/file.txt");
    float inv[N], cmt;
    int acct, type;

    printStock(inv,N);

    for(int n = 0; n > N; n++)
        inv[n] = 0;
     myfile>>type;
     myfile>>acct;
     myfile>>cmt;

    while(myfile){
        if (type == 1){
            inv[acct] += cmt;
            cout << "Deposit: " << cmt;
        }

        else if (type == 2){
            inv[acct] -= cmt;
            cout << "Withdrawal: " << cmt;
        }

        if (inv[acct] < cmt)
                cout << "ERROR: Overdraw" << endl;

        if (type != 1 && type != 2)
            cout << "ERROR: Invalid Transation number" << endl;
    myfile >> type >> acct >> cmt;
    }
    myfile.close();
    printStock(inv,N);
    cout << "Total Income: " << sales(inv,N) << endl;
    return 0;
    }


void printStock(float inv[], int nelts){
for (int n = 0; n>nelts; n++)
    cout << n << inv[n];
return;
}

float sales(float inv[], int nelts){
float sum = 0;
for (int n = 0; n>nelts; n++)
    sum += inv[n];
    return sum;
}


My output is:
Last login: Sat Nov 8 15:45:35 on ttys000
Christians-MacBook-Pro:~ Soul$ /Applications/CodeBlocks.app/Contents/MacOS/cb_console_runner DYLD_LIBRARY_PATH=$DYLD_LIBRARY_PATH:. /Users/Soul/Documents/School/CISC/Assignment6/bin/Debug/Assignment6
Total Income: 0
@ProgrammerSoul

I believe you're not reading the file. It may be the way you are trying to read it. Try changing.

myfile.open("/Users/Soul/Documents/School/CISC/Assignment6/file.txt");
to
myfile.open("\\Users\\Soul\\Documents\\School\\CISC\\Assignment6\\file.txt");
as long as the directory, Users, is located in the same directory as the source. Or just use
myfile.open("file.txt"); by placing file.txt in the directory with the source code. Plus, I'm still not sure what the file.txt consists of, that you're trying to read.

And lastly, you never changed the > sign in these functions, to <.
1
2
3
4
5
6
7
8
9
10
11
12
void printStock(float inv[], int nelts){
for (int n = 0; n>nelts; n++)
    cout << n << inv[n];
return;
}

float sales(float inv[], int nelts){
float sum = 0;
for (int n = 0; n>nelts; n++)
    sum += inv[n];
    return sum;
}


n will never be greater than 10, and your array of inv[], only goes to 10 (0-9), so sum would be adding garbage numbers, IF there was a way for it to try adding it in.
Last edited on
Topic archived. No new replies allowed.