Go4Expert (http://www.go4expert.com/)
-   C# (http://www.go4expert.com/forums/c-sharp/)
-   -   Logical Error (http://www.go4expert.com/forums/logical-error-t24275/)

 tom_289 27Dec2010 07:22

Logical Error

Code given below, suppose to give
hourly pay * number of hours + if hours greator then 37 then calculate rest with given rate (overtime)
and display final result

but its just multiplying pay rate hourly with pay rate for overtime hourly

and i made it in VS 2010 windows application but error is logical as i said.... and its a payroll calculator
Code:

```using System; using System.Collections.Generic; using System.Linq; using System.Text;   namespace PayrollSystem {     public class partTimeEmployees : Employee     {         private decimal wage;      // wage per hour of work         private double hoursWorked; // hours worked during week         private decimal overTimeWage; // wage per hour for over time           // constructor         public partTimeEmployees(string firstNameValue, string LastNameValue,           decimal wageValue, double hoursWorkedValue, decimal overTimeWageValue)             : base(firstNameValue, LastNameValue)         {             Wage = wageValue;             HoursWorked = hoursWorkedValue;             OverTimeWage = overTimeWageValue;         }           // property Wage         public decimal Wage         {             get             {                 return wage;             }               set             {                 // ensure non-negative wage value                 if (value > 0)                     wage = value;             }         }         // property HoursWorked         public double HoursWorked         {             get             {                 return hoursWorked;             }               set             {                 // ensure non-negative hoursWorked value                 if (value > 0)                     hoursWorked = value;             }         }         // property over time Wage         public decimal OverTimeWage         {             get             {                 return overTimeWage;             }               set             {                 // ensure non-negative wage value                 if (value > 0)                     overTimeWage = value;             }         }           // override base-class method to calculate         // HourlyWorker earnings         public override decimal Earnings()         {         // compensate for overtime (paid "time-and-a-half")         if ( HoursWorked <= 37 )         {             return Wage * Convert.ToDecimal( HoursWorked );         }           else         {             // calculate base and overtime pay             decimal basePay = Wage * Convert.ToDecimal(37);             decimal overtimePay = OverTimeWage * Convert.ToDecimal( HoursWorked - 37);               return basePay + overtimePay;         }         }           // return string representation of HourlyWorker         public override string ToString()         {             return "Part Time Employee: " + base.ToString();         }     }   }```

 All times are GMT +5.5. The time now is 17:47.