title: Computing net salary of employees using functions - C++
body: <p>Below is what I have thus far. I can't seem to figure out what I'm doing wrong. I think the input validation functions that I have are incorrect as well. Original problem is: </p>
  
  <p>Write a program a program that would compute the net salary of employees. The program should prompt the user to input number of hours worked and the hourly wage.  Employees pay 17.5% of their gross salary as social security contribution. All employees pay 20% tax on their gross salary. Employees with gross salary less than 2500, pay 10% tax on their gross salary. Your program should use  the following functions;     </p>
  
  <p>a.  computeGross :This function calculates the gross salary based on the  number of hours worked and  hourly wage. The gross salary calculated is returned to the main function.</p>
  
  <p>b.  computeDeductions: This function accepts as input , the gross salary , computes the social security and tax deductions and returns the total deductions to the main function</p>
  
  <p>c.  computeNet: This function accepts as input the gross salary, deductions and prints out  The gross salary, total deductions and the net salary .</p>
  
  <p>d.  validateHours: This function  is used for input validation. It determines if the number of hours provided by the user is valid or not. The number of hours worked in a pay period cannot exceed 150 and cannot be negative.</p>
  
  <p>e.  validateWage: This function  is used for input validation. It determines if the hourly wage provided by the user is valid or not. The hourly wage cannot exceed 200 and cannot be negative.</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;iomanip&gt;
  using namespace std;
  
  // Declare Functions
  double computeGross(double hoursWorked, double hourlyWage);
  double computeDeductions(double grossPay);
  double computeNet(double grossPay, double deductions);
  void validateHours(double hoursWorked);
  void validateWage(double hourlyWage);
  
  int main()
  {
      // Declare Variables
      double hoursWorked = 0;
      double hourlyWage = 0;
      double grossPay = 0;
      double deductions = 0;
      double netSalary = 0;
  
  // Get the hours worked and hourly wage
  cout &lt;&lt; "Please enter the amount of hours worked (HH.MM): " &lt;&lt; endl;
  cin &gt;&gt; hoursWorked;
  cout &lt;&lt; "Please enter in your hourly wage: $" &lt;&lt; endl;
  cin &gt;&gt; hourlyWage;
  
  // Output the results
  cout &lt;&lt; fixed &lt;&lt; setprecision(2)
       &lt;&lt; "The net salary is: $" &lt;&lt; netSalary &lt;&lt; endl;
  
      return 0;
  }
  
  // compteGross() function - get gross salary based on hours worked and hourly wage.
  double computeGross(double grossPay, double hoursWorked, double hourlyWage)
  {
  return grossPay = hoursWorked * hourlyWage;
  }
  
  // computeDeductions() function - gets salary and calculates deductions
  double computeDeductions(double deductions, double grossPay)
  {
  
      if(grossPay &lt; 2500)
      {
      deductions = (grossPay * .10) * .175;
      }
      else
      {
      deductions = (grossPay * .20) * .175;
      }
  
  return deductions;
  
  }
  
  // computeNet() function - prints out gross salary,total deductions and net    salary
  double computeNet(double netSalary, double grossPay, double deductions)
  {
  netSalary = grossPay - deductions;
  
  cout &lt;&lt; "The gross salary is: $" &lt;&lt; grossPay &lt;&lt; endl;
  cout &lt;&lt; "The total deductions are: $" &lt;&lt; deductions &lt;&lt; endl;
  cout &lt;&lt; "The net salary is: $" &lt;&lt; netSalary &lt;&lt; endl;
  return netSalary;
  }
  
  // validateHours() function - input validation; hours worked can;t exceed 150  or be neg.
  void validateHours(double hoursWorked)
  {
      if(hoursWorked &lt; 0 || hoursWorked &gt; 150)
      {
          cout &lt;&lt; "Error! Hours can't be negative or exceed 150\n";
      }
  }
  
  // validateWage() - Input validation; wage can't exceed 200 or be   negative
  void validateWage(double hourlyWage)
  {
      if(hourlyWage &lt; 0 || hourlyWage &gt; 200)
      {
      cout &lt;&lt; "Error! Wage can't be negative or exceed 200\n";
      }
  }
  </code></pre>