Trying to write a function that adds all the numbers in an array

I'm trying to write a function that takes adds all of the numbers from an array. I'm not understanding the error code
invalid conversion from 'int' to 'int*' [-fpermissive]
total = total_sales(sales[i]);

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

using namespace std;

int main()
{

int i=0, sum, total, sales[21], total_sales(int sales[]);
ifstream in_stream;
char sales_file[16];


cout << "What is the name of the file for the sales?\n";
cin >> sales_file;
in_stream.open(sales_file);
while(!in_stream.eof())
{
in_stream >> sales[i];
i++;
}
int num_of_locations = sales[0];

total = total_sales(sales[i]);
cout << "The total of all sales at all locations is " << total << " .\n";

in_stream.close();

int total_sales(int sales[]);
   for (i=1, i<21, i++)
   {
      sum = 0;
      sum += sales[i];
      }
   
   return sum
   }


}
Your code indeed does not compile. There is more errors than that once this error has been fixed.

Additionally, you don't know how to write a for-loop correctly.
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
#include <iostream>
#include <fstream>
#include <string>

using namespace std;

int main()
{

int i=0, sum, total, sales[21], total_sales;
ifstream in_stream;
char sales_file[16];


cout << "What is the name of the file for the sales?\n";
cin >> sales_file;
in_stream.open(sales_file);
while(!in_stream.eof())
{
in_stream >> sales[i];
i++;
}
int num_of_locations = sales[0];

total = total_sales;
cout << "The total of all sales at all locations is " << total << " .\n";

in_stream.close();

   for (i=1; i<21; i++)
   {
      sum = 0;
      sum += sales[i];
   
   }

   return sum;

}

Here is the code and contains no compiler errors. It is up to you to fix all remaining mistakes in your program.
closed account (48T7M4Gy)
http://www.cplusplus.com/forum/beginner/202079/
Topic archived. No new replies allowed.