please help with this program. I need to calculate the highestSalesand the averageSales using float funtions and displayOutput using void, I wrote the program but I can not get the output I get a lot of confusion. please help. when I'm trying to compile i get the error cpp:5
too few arguments to function `float getSales(float, float, float, float)'
please check the program bellow.

#include <iostream>
using namespace std;

float getSales(float sales1, float sales2, float sales3, float sales4)
{
return (sales1 + sales2 + sales3 + sales4);
cout << "enter sales figure until 4: "<<endl;
cin >>sales1 >>sales2 >>sales3 >>sales4;
cout <<endl;

}

float findHighest(float sales1, float sales2, float sales3, float sales4)
{
return (sales1, sales2, sales3, sales4);
}
float calcAverage(float sales1, float sales2, float sales3, float sales4)
{
return (sales1 + sales2 + sales3 + sales4) /4;
}
void displayOutput (float highestSales, float averageSales)
{
cout.setf(ios::fixed);
cout.precision(2);
highestSales = 0;
averageSales = 0;
}

int main()
{
float sales1,
      sales2,
      sales3,
      sales4;
float averageSales;
float highestSales;

for (int i = 0; i < 4; i++)
{
    sales1 = getSales();
    sales2 = getSales();
    sales3 = getSales();
    sales4 = getSales();

    highestSales = findHighest(sales1, sales2, sales3, sales4);

    averageSales = calcAverage(sales1, sales2, sales3, sales4);

    displayOutput(highestSales, averageSales);
}
return 0;
}

The error as far as the compiler is concerned is straightforward. The function wants four parameters. You give it none.

There are deeper problems though. What is getSales supposed to do? You have a return statement on line 6. Hence lines 7, 8, and 9 will never execute.

What do you want the getSales function to do (in English, not code)? Once that is clear, it will be more obvious how to fix this.

As getSales(); has 4 argument, you provided none, so it shows error.

Your line no. 7 an 8 can be placed in main() and then the getSales(); can be called like this.

int main()
{ 

    cout << "enter sales figure until 4 : ";

    cin >>sales1 >>sales2 >>sales3 >>sales4;

    float answer;

    answer =  getSales( sales1, sales2, sales3, sales4 );

    // rest of your code


}

For loop here is not necessary, as number of variables are 4.

Also in line 15, you need to return the highest value. return (sales1, sales2, sales3, sales4); will not give you the highest and is not correct. Find the highest by implementing some algorithm and then return THAT value.

thank you! after I did the changes, the program is compiling and letting me to input sales figure, but it does not do the calculation and display the output
Please can anyone help me what to modify to make the calculation and the output
This is the program

#include <iostream>


    using namespace std;

    float getSales(float sales1,  float sales2,  float sales3,  float sales4)
    {

    cout << "enter sales figure until 4: "<<endl;
    cin >>sales1 >>sales2 >>sales3 >>sales4;
    cout <<endl;
    return (sales1, sales2, sales3, sales4);

    }

    float findHighest(float sales1, float sales2, float sales3, float sales4)
    {
    return (sales1, sales2, sales3, sales4);
    }
    float calcAverage(float sales1, float sales2, float sales3, float sales4)
    {
    return (sales1 + sales2 + sales3 + sales4) /4;
    }
    void displayOutput (float highestSales, float averageSales)
    {

    cout.setf(ios::fixed);
    cout.precision(2);
    highestSales = 0;
    averageSales = 0;
    }

    int main()
    {
    float sales1,
          sales2,
          sales3,
          sales4;
    float averageSales;
    float highestSales;

    for (int i = 0; i < 4; i++)
    {
         float sales1, sales2, sales3, sales4;
       getSales(sales1, sales2, sales3, sales4);

        highestSales = findHighest(sales1, sales2, sales3, sales4);

        averageSales = calcAverage(sales1, sales2, sales3, sales4);

        displayOutput(highestSales, averageSales);
    }
    return 0;
    }

Please use consisent formatting so we can read the code easier...

return (sales1, sales2, sales3, sales4);
Illegal format. Look up the return statement again...

... but it does not do the calculation and display the output

Meaning what? Nothing gets output? Bad information? Crashes? When asking for help ALWAYS
1) explain what happened
2) what you expected instead
3) the input
4) and anything else you need us to know about the program because YOU wrote it, WE didn't.

Hi queos,

It looks as though you haven't quite understood about pass-by-reference and pass-by-value yet. Taking this function, for example:

float getSales(float sales1, float sales2, float sales3, float sales4)
{
    cout << "enter sales figure until 4: "<<endl;
    cin >>sales1 >>sales2 >>sales3 >>sales4;
    cout <<endl;
    return (sales1, sales2, sales3, sales4);
}

it looks as though you want to return values in the parameters you pass into the function (sales1, sales2, sales3, sales4). It's complicated further by the return statement you're using.

If you want to populate those parameters with the values input, you'll need to pass-by-reference, and you won't need the return statement.

The gap in your understanding is big enough that I don't think posting the correct code for you will help. I think you need to go back to your reference book, or do a search on google, and get to grips with pass-by-reference and pass-by-value before you try to go any further with this particular programme. It's a fundamental concern that you'll need to master for pretty much any programme that you're going to write. Master that, and try again.

And take another look at returning values from functions, too.

Good luck with your coding.

Edited 4 Years Ago by Bob

This article has been dead for over six months. Start a new discussion instead.