### Homework help

I am having trouble understanding my teacher's explanation. I need help with this assignment.

3.Given the following coded function

double calcBonus( int sold, double bonusRate)
{
double bonusAmount = 0.0;
bonusAmount = sold * bonusRate;
return bonusAmount;
}

code the prototype and the function call.

You need to write a function prototype and then

this is an example:

 ``12345678910111213141516171819202122232425`` ``````//functionBehavior.cpp //implement a prototype and function call. #include using std::cout; using std::endl; #include using std::string; void displayMessage(string message); //function prototype int main(){ string message="Hello World!\n"; displayMessage(message); //function call return 0; //indicates success }//end main //function implementation void displayMessage(string message){ cout<

 ``` Eyenrique-MacBook-Pro:C++ Eyenrique\$ ./functionBehavior Hello World! ```
So in the example I gave then.

the prototype would be:

double calcBonus(int sold, double bonusRate);

the function call would be:

calcBonus(bonusAmount);

does this look correct?
Your function prototype is right but,
function call NO. `calcBonus(bonusAmount);`

 `` `` ``calcBonus(sold,bonusRate);``

Think that, your function calcBonus expects sold and bonusRate variables to
calculate bonusAmount.
Last edited on
I have another problem for you to look at please:

given the following data and prototype

double average = 0.0;
double calcAverage (double, double);

and given the following sample function call

average = calcAverage (34.3, 43.3); // any two double values as parameters

code the function named calcAverage( )

Here is what I came up with:

double calcAverage(double, double)
{

double average = 0.0;
cout<<"enter two numbers";
cin>>x >>y;
average = x * y / 2;

}

You need to do a return statement within the function.

 ``1234`` ``````double calAverage(double x, double y) { return (x * y) / 2; }``````

When you call a data type in the front, that isn't void, you must return a value that is that data type. So with double in front of the function name, you must return a number that is a double.

Here is what it would look within a piece of code:

 ``12345678910`` ``````//the function that was created previously goes here int main() { double average = 0.0; cout << "enter two numbers: "; cin >> x >> y; average = calAverage(x, y); //this puts the two values within the function then sets the return value into average cout << average; //shows average return 0; //end program }``````
I can figure out this:

 ``123456`` ``````double calcAverage(double value1,double value2){ double sum; sum=value1+value2; return sum/2; }//end function calcAverage ``````
Topic archived. No new replies allowed.