Cannot convert `float*' to `float' errors

Hi I keep getting these 3 errors that I'm not sure how to debug:

ERROR: In function `int main()';

ERROR: Line 44: Cannot convert `float*' to `float' for argument `1' to `float average_Sales(float, int)'

ERROR: Line 48: cannot convert `float*' to `float' for argument `1' to `void Standard_comparison(float, float, bool, int)'


Can someone please give me some pointers on what I'm doing wrong? I spent the all afternoon trying to get this to work but I'm stuck on this.

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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
#include <iostream>
#include <fstream>
#include <iomanip>
using namespace std;

//=============================================================================
// Function prototypes
float average_Sales(float, int);
void Standard_comparison(float, float, bool, int);
int above_below(bool, int);
void print_Result(int, double, int, int);

//=============================================================================
// Main function
int main()
{
	// Is this the parallel array????
	int average;
	float standard[12]={23.0, 33.1, 21.0, 23.5, 54.0, 34.3,
						35.0, 45.0, 56.3, 45.6, 34.0, 55.0};
			  
	float sales[12]; 
	bool meet[12];

	ifstream fp;
	int id=0;
	
	fp.open("sales.dat");
	
	while(fp>>sales[0])
    {
      // Assign value from 1-7 to each line of data
      id++;

      // Enter the values into the array
	  for (int i=1; i<11; i++)
		{
			fp>>sales[i];
		}


      // Get the average
      float average;
      average = average_Sales(sales, 12);


      // Compare sales and standard, populate the meet array
      Standard_comparison(sales, standard, meet, 12);

	  
	  //compute how many months meet the standard
      int above;
      above = above_below(meet, 12);

      //compute how many months are below standard
      int below =  12-above;  

      //display the department stat in a single line 
      //the performance can be displayed on the fly
      print_Result(id, average, above, below);
    }
}

//===============================================================================
// Calculates the annual average for a particular department
float average_Sales(float sales[], int size)
{
	float sum;
	for (int i=0; i<12; i++)
    {
      sum+=sales[i];
    }
	float average;
	average = sum/12;
}

//================================================================================
// Compare sales figures with standard array and store stats in new (bool) array
void Standard_comparison(float sales[], float standard[], bool meet[], int size)
{
	for (int i=0; i<12; i++)
	{	
	if (sales[i]>standard[i])
		meet[i]=true;
	else
		meet[i]=false;	
	}
}

//==================================================================================
// Determine whether the monthly sales were above or below average
int above_below(bool meet[], int size)
{
	int counter =0;
	for (int i=0; i<12; i++)
    {
      if (meet[i]= true)
		counter ++;
    }
}

//===================================================================================
void print_Result(int id, float average, int above, int below)
{
cout << setprecision(2) << fixed;
cout << "Store Statistics\n";
cout << "Dept  " << "Average  " << "Above     " << "Below     " << "Performance" << endl;
cout << "=======================================================================\n";
for (int i=0; i<7; i++)
	{
		cout << id++ << average << above << below << endl;
	}
}
Last edited on
Those errors are brought up because of the way your function headers are declared. You declare many of the parameters as float and not float[]. They must be written the way they are down below the main function. You are passing in a pointer to the arrays but the function header parameters only specify a value of float. Look over the function headers.
Last edited on
the function prototype you declared above doesn't match the function definition below. You have to correct the declaration.

1
2
3
4
5
6
//=============================================================================
// Function prototypes
float average_Sales(float[], int);
void Standard_comparison(float [], float [], bool [], int );
int above_below(bool [], int );
void print_Result(int , float , int , int );
Hi,

Prefer double over float. Double is the default because the precision of float is easily exceeded, and you can avoid unnecessary implicit conversions. For example on line 19, all those number literals are actually double, but then the compiler has to convert them to float.

float has 6 or 7 significant figures, while double has 15 or 16 depending on the implementation.

Perhaps the only reason one might use float is if some library requires it - typically a graphics library.
Thanks for the help everyone. I implemented the changes to the function prototypes and I also switched everything from float to double. The program now compiles and runs. Thanks again :)
Topic archived. No new replies allowed.