Click here to Skip to main content
15,881,172 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
Hi,
I need to calculate monthly salary with the normal calculations like allowances. My Question is how to calculate the salary with the days he came to work. Eg: total working days is 31 for march and an employee present for 20 days and 11 days took leave. He has 3 casual leaves. Then how can i calculate the salary with these criterias and also with normal salary calculations. Help me with some code and links,
Posted
Updated 7-Jun-12 20:59pm
v2
Comments
Sandeep Mewara 8-Jun-12 2:25am    
This is simply maths with direct divide & multiple. What is confusing here to you? Which part you are unable to get?

Code or link for this? Why?
RDBurmon 8-Jun-12 3:20am    
OK , So Gowtham , Please see below answers and suggestions given by CP team members. Read each one carefully as each one have very very important thoughts include in it by CP professional. And then I would like to Mark it as answer for your question so that CP team know you have got your solution and no need to focus on this question posted by you as forum will display it as "[Solved]" Thank You.

Salary for the month = Monthly Salary / Total no. of days in the month * (days worked + paid leaves)
paid leaves can be calculated as,
if Leaves taken > available leaves<br />
  Paid Leaves = Available Leaves<br />
else<br />
  Paid leaves = Leave Taken


Now you need to update the available leaves.
Available Leaves = Available Leaves - paid Leaves

This is all simple Maths! You just need to write proper language syntax to implement it in whatever language you are coding.
 
Share this answer
 
Comments
Abhinav S 8-Jun-12 2:28am    
Correct. 5.
Manas Bhardwaj 8-Jun-12 2:34am    
This is correct 5+
Looks like homework. And by the way it has nothing to with C# or .Net for that matter. You need the formula to calculate salary and write it in C# which shouldn't be difficult anyways.

Apart from that, what you wrote is also not logical. Out of 31 days, someone comes to office for 20 days and takes leave of 11 days. googI expect there are weekends as well :).

Google is your friend, try to search [^]and I am sure you fill find where you can take inpiration from. :)
 
Share this answer
 
Comments
Abhinav S 8-Jun-12 2:28am    
The OP has posted a homework question. 5.
Manas Bhardwaj 8-Jun-12 2:34am    
Thanks!
Hello Gowtham ,

My suggestion is to divide basic salary by number of days in a month and then multiply it by number of non-paid leaves and deduct that amount from total salary.

For Example
Employee "John Kerry" has salary stucture as (Basic 5000.00 + HRA 2500.00 + Allowances 1500.00 + Expenses 750.00 = 9750.00) . And He had taken leaves in March for 13 days and those are non paid leaves then His salary for March would be

Basic Salary Per Day5000/31161.29
Per day basic salary x Leaves161.29 x 13 2096.77
Total Salary including variables 9750.009750.00
Total Salary for Mar9750.00 - 2096.77 7653.23



Hope this helps , If yes then plz accept and vote the answer. Any queries / questions on this are always welcome.

Thanks & Regards
RDBurmon.Sr.Software Engineer
 
Share this answer
 
Comments
Manas Bhardwaj 8-Jun-12 2:34am    
Well explained +5!
RDBurmon 8-Jun-12 3:20am    
Thank You Manas.
Here is the calculation that you could use -

Salary = ((days in month) - (days leave taken) + (causal leave)) * (basic salary)/ (days in month) 


Variations could be based on days in month and leap year.

There can be tons of more variations to this, based on salary components etc - so you should really try this on your own.
 
Share this answer
 
v3
Comments
Manas Bhardwaj 8-Jun-12 2:34am    
Right +5!
Abhinav S 8-Jun-12 2:43am    
Thanks.
C#
namespace CAMInheritence
{
    class ClsBranch
    {
        int Bcode;
        string BName, BAddress;
        public void GetBData()
        {
            Console.WriteLine("Enter Branch Details are:-");
            Bcode = Convert.ToInt32(Console.ReadLine());
            BName = Console.ReadLine();
            BAddress = Console.ReadLine();
        }
        public void DisplayBData()
        {
            Console.WriteLine("Branch code is:-"+Bcode);
            Console.WriteLine("Branch Name is:-" + BName);
            Console.WriteLine("Branch Address is:-"+BAddress);
        }
    }
    class ClsEmployee:ClsBranch
    {
        int Empid,EAge;
        string EName,EAddress;
        public void GetEmpData()
        {
                Console.WriteLine("Enter Employe Details are:-");
                this.Empid=Convert.ToInt32(Console.ReadLine());
                this.EName=Console.ReadLine();
                this.EAddress=Console.ReadLine();
                this.EAge=Convert.ToInt32(Console.ReadLine());
        }
        public void DisplayEmpData()
        {
            Console.WriteLine("Employee Id is:-"+Empid);
            Console.WriteLine("Employee Name is:-"+EName);
            Console.WriteLine("Employee Address is :-"+EAddress);
            Console.WriteLine("Employee Age is:-"+EAge);
        }
    }
    class ClsSalary:ClsEmployee
    {
        double Basic,DA,HRA,GROSS;
        public void GetSalData()
        {
            Console.Write("Enter Basic Salary:- ");
            Basic=Convert.ToInt32(Console.ReadLine());
        }
        public void Calculate()
        {
            DA    = 0.4*Basic;
            HRA   = 0.3*Basic;
            GROSS = Basic+DA+HRA;
        }
        public void DisplaySalData()
        {
            Console.WriteLine("Employee Basic is:-"+Basic);
            Console.WriteLine("Employee DA is:-"+DA);
            Console.WriteLine("Employee HRA is :-"+HRA);
            Console.WriteLine("Employee Gross is:-"+GROSS);
        }
    }
    class ClsMLInheritence
    {
      static void Main(string[] args)
        {
          ClsSalary obj1=new ClsSalary();
          obj1.GetBData();
          obj1.GetEmpData();
          obj1.GetSalData();
          obj1.Calculate();
          obj1.DisplayBData();
          obj1.DisplayEmpData();
          obj1.DisplaySalData();
          Console.ReadLine();
      }
        }
    }
 
Share this answer
 
Comments
Richard MacCutchan 6-Apr-15 5:48am    
This question is almost three years old. Please do not post in old questions.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900