``````// file: PayrollFunctions.cpp
// Computes and displays gross pay and net pay given an hourly
// rate and number of hours worked. Deducts union deus of \$15
// if gross salary exceeds \$100; otherwise,deducts no dues.

#include <iostream>
using namespace std;

// Functions used...
void instructUser();
float computeGross (float, float);
float computeNet (money);

const float MAX_NO_DUES = 100.00;
const float dues = 15.00;
const float MAX_NO_OVERTIME = 40.0;
const float OVERTIME_RATE = 1.5;

int main()
{
float hours;
float rate;
float gross;
float net;

// Display user instructions
instructUser();

//Enter hours and rate
cout << "hours worked: ";
cin  >> hours;
cout << " Hourly rate: \$";
cin  >> rate;

gross = computeGross (hours,rate );

// Compute net salary
net = computeNet(gross);

// Print gross and net.
cout << " Gross salary is \$" << gross<<endl;
cout<< " net salary is \$ " << net << endl;

return 0;
}

// Display user instructions
void instructUser()

{
cout << "This program compute gross and net salary . " << endl;
cout << " A dues amount of " << dues << "is deducted for"<< endl;
cout << " an employee who earns more than " << MAX_NO_DUES << endl<<endl;
cout << " Overtime is paid at the rate of " << OVERTIME_RATE << endl;
cout<< "times the regualr rate fro hours worked over "<< MAX_NO_OVERTIME <<endl << endl;
cout << "on separate lines after the promts. " <<endl;
cout << " Press <return > after typing each number . " << endl << endl;
}

// Find the gross pay

float computeGross
(float hours,float rate)

{

// Local data . . .
float gross;       // result : gross pay (dollars)
float regularPay;  // pay for first 40 hours
float overtimePay;  // pay for hours in excess of 40

// Compute gross pay.
if ( hours > MAX_NO_OVERTIME)
{
regularPay= MAX_NO_OVERTIME *rate;
overtimePay = (hours - MAX_NO_OVERTIME) * OVERTIME_RATE *rate;
gross = regularPay + overtimePay;
}

else
gross = hours * rate;

return gross;
} // end computeGross

// Find the net pay

float computeNet

(float gross)

{

//Local data...
float net;

// Compute net pay.
if ( gross > MAX_NO_DUES)
net = gross - dues ; // deduct dues amount

else
net = gross;

return net;
}//end computeNet
``````

i got it, but can you explain me the difference between
float computeGross (float, float);
float computeNet (float money);
thansk

i got it, but can you explain me the difference between
float computeGross (float, float);
float computeNet (float money);
thansk

First of all you need to use code-tags always .. Nobody will even look at your code if its not easy to read, so without going through your code i'll just ans the question above..

its a simple difference, computeGross has 2 parameters passed to it, both float. computeNet has only parameter passed to it 'money' which is a float too. what is it that you dont understand in this?

Lets say you have a function foo which takes a float as an argument. You can declare foo as `void foo(float);` or `void foo(float myFloat);` myFloat is your variable name, and not necessarily needed in your declaration.

mean that myfloat is a new variable that I don't declare in the main, and declare locally in the function rite

Yes , when you are calling a function by call by value method as you are doing in your code you are making a local copy. If you need the change to be reflected in main also you should use reference method

As a matter of fact, no.

The name of an argument in a function declaration (ie. "myFloat" in `void foo(float myFloat);` ) is generally ignored by the compiler. It is generally used simply to give information to the programmer (eg by providing a descriptive name, rather than adding an additional comment). That argument name has no relationship to any variable within the caller (eg in main()).

As a matter of fact, no.

The name of an argument in a function declaration (ie. "myFloat" in `void foo(float myFloat);` ) is generally ignored by the compiler. It is generally used simply to give information to the programmer (eg by providing a descriptive name, rather than adding an additional comment). That argument name has no relationship to any variable within the caller (eg in main()).

But when we define a function the myFloat will be a local variable created in the function itself.

Not quite. It is quite legitimate to do this;

``````void func(float aName);   // declaration (which may come from an #include'd header)

void func(float AnotherName)
{
std::cout << AnotherName << '\n';
}``````

In other words, the argument name in a function declaration is not required to match the argument name in the function definition (ie implementation).

i agree to you grumpier, but i was talking about the definition of a function not the declaration.
i wanted to say that the definition will itself create a local copy with that variable name.