This is my first program using functions. I believe I have an issue with returning, and sending values since my compute salary function gives initial values of zero.
Inside the function body you call another function payCheck. This function calculates amount and returns it. But inside function you do not use returned value of the amount. So the function payCheck was called in vain. It calculated the amount but you did not use it.
Let consider a simple example
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
#include <iostream>
double f( double x )
{
x = x + 10.0;
return x;
}
int main()
{
double x = 0.0;
f( x );
std::cout << "x = " << x << std::endl;
}
What value of x will be printed?
It is obvious that inside main the value of x will not be changed. So 0 will be printed.
But if you change the code inside main the following way
x = f( x );
then x get the value returned by f. And instead of 0 the new value that is 10 will be printed.
Another example
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
#include <iostream>
double f( double&x )
{
x = x + 10.0;
return x;
}
int main()
{
double x = 0.0;
f( x );
std::cout << "x = " << x << std::endl;
}
Here the function gets an argument by reference. So any changes of x inside the function will change the original x and 10 will be outputed.