# Thread: Help with Code (function)

1. ## Help with Code (function)

Can some1 help tell me y my function keeps having errors? I want the user to enter 4 price s, total sales each products sale is worth 25% of the sale. I wanna take these 4 products and calculate an average and return the value to the variable slsAvg. Is my function prototype, call, and function that much off?

Code:
```double calcAveragefunc(double towers, double monitors, double printers, double desks, double slsAvg)
{
return slsAvg;
}

using namespace std;

int main(){

double towers;
double monitors;
double printers;
double desks;
double totalProductSales;
double slsAvg;

cout << "Enter towers price: ";
cin >> towers;
cout << "Enter monitors price: ";
cin>> monitors;
cout << "Enter printers price: ";
cin >> printers;
cout << "Enter desks price: ";
cin >> desks;

totalProductSales = towers + monitors + printers + desks * 25;

slsAvg = totalProductSales / 4;

return 0;
}
double calcAveragefunc(double towers, double monitors, double printers, double desks, double slsAvg)
{
return slsAvg;
}```

2. It's late, but what exactly is that *25 for?

a+b+c+d/4 is your average. Or perhaps within your question there's something that I'm missing.

Code:
```    void calculate(double a, double b, double c, double d)
{
double e=a+b+c+d;
double pcent=e/4;
cout<<pcent;
}

int main()
{
double aa, bb, cc, dd;
cout<<"enter aa";
cin>>aa;
cout<<"enter bb";
cin>>bb;
cout<<"enter cc";
cin>>cc;
cout<<"enter dd";
cin>>dd;
calculate(aa,bb,cc,dd);
cin.get();
}```

Popular pages Recent additions