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.
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.
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;
}
#include <iostream>
#include <fstream>
#define N 10
usingnamespace 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;
}
elseif (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
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.