does not evaluate to a function - anyone know why?

This is a discussion on does not evaluate to a function - anyone know why? within the C++ Programming forums, part of the General Programming Boards category; lowestSales(salesTotAry[0], salesPer);// function // call does not evaluate to a function // The function is: float lowestSales(float *salesTotAry, int salesPer) ...

  1. #1
    Registered User
    Join Date
    Oct 2001
    Posts
    28

    Question does not evaluate to a function - anyone know why?

    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

  2. #2
    Registered User
    Join Date
    Aug 2001
    Posts
    61
    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.

  3. #3
    Registered User
    Join Date
    Oct 2001
    Posts
    28

    thanks, still no joy

    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

  4. #4
    zen
    zen is offline
    of Zen Hall zen's Avatar
    Join Date
    Aug 2001
    Posts
    1,007
    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

  5. #5
    Registered User
    Join Date
    Aug 2001
    Posts
    155
    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.

  6. #6
    Registered User
    Join Date
    Oct 2001
    Posts
    28

    Wink

    Thanks you all for your help. I got the program to work.
    rc7j

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Post your games here...
    By Hammer in forum Game Programming
    Replies: 132
    Last Post: 02-28-2013, 09:29 AM
  2. Replies: 4
    Last Post: 05-13-2011, 09:28 AM
  3. Undefined Reference Compiling Error
    By AlakaAlaki in forum C++ Programming
    Replies: 1
    Last Post: 06-27-2008, 12:45 PM
  4. <Gulp>
    By kryptkat in forum Windows Programming
    Replies: 7
    Last Post: 01-14-2006, 01:03 PM
  5. Question..
    By pode in forum Windows Programming
    Replies: 12
    Last Post: 12-19-2004, 07:05 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21