lowestSales(salesTotAry[0], salesPer);// function // call does not evaluate to a function
// The function is:
float lowestSales(float *salesTotAry, int salesPer)
the perameters match up
??
lowestSales(salesTotAry[0], salesPer);// function // call does not evaluate to a function
// The function is:
float lowestSales(float *salesTotAry, int salesPer)
the perameters match up
??
rc7j
Change:
lowestSales(salesTotAry[0], salesPer);
to either
lowestSales(&salesTotAry[0], salesPer);
or
lowestSales(salesTotAry, salesPer);
the function call, lowestSales(salesTotAry[0], salesPer);, is trying to pass the value stored in, salesTotAry[0], to the function.
thanks, I tried both suggestions, same results. Must be somewhere else?
#include <iostream>
#include <cstdlib>
using namespace std;
float lowestSales(float *salesTotAry, int salesPer);
int main()
{
int countSales, salesPer;
float indivSalesTotal = 0, salesTotal = 0, lowestSales = 0, highestSales = 0;
;
cout << "Enter the number of salespersons working for the firm: " << endl;
cin >> salesPer;
float *salesTotAry;
if ((salesTotAry = new float) == NULL)
{
cerr << "Out of memory" << endl;
exit(EXIT_FAILURE);
}
for(countSales = 0; countSales < salesPer; countSales++)
{
cout << "Enter the sales totals for each person " << endl;
cin >> salesTotAry[countSales];
if (lowestSales > salesTotAry[countSales])
lowestSales = salesTotAry[countSales];
if (highestSales < salesTotAry[countSales])
highestSales = salesTotAry[countSales];
salesTotal += salesTotAry[countSales];
}
cout << "The total sales is " << salesTotal << endl;
cout << "The average sales is " << salesTotal / countSales << endl;
cout << "The lowest sales is " << lowestSales(salesTotAry, salesPer) << endl; // "does not evaluate to a function"
cout << "The highest sales is " << highestSales << endl;
lowestSales(&salesTotAry[0], salesPer); // debug code resp: "does not evaluate to a function"
delete salesTotAry;
return 0;
}
float lowestSales(float *salesTotAry, int salesPer)
{
int lowest = salesTotAry[0];
for (int count = 1; count < salesPer; count++)
{
if (salesTotAry[count] > salesTotAry[count])
lowest = salesTotAry[count];
}
return lowest;
}
rc7j
You have used the same identifier for a variable and a function. Also your memory allocation should be -
salesTotAry = new float[salesPer]
otherwise you just allocating space for one float.
zen
I can;t say this is wrong:
lowestSales(&salesTotAry[0], salesPer);
but isn't this easier?
lowestSales(salesTotAry, salesPer);
It turns out the compiler interprets the name of an array as the address of the first element of the array. Sometimes these type of shortcuts make life easier, and sometimes they don't. I like this one, though.
Thanks you all for your help. I got the program to work.
rc7j