Hello coders, in this post we will know how to calculate salary of an employee using Go Programming language.
We will calculate the salary of the employee, including all the perks which is provided to him.
Dearness Allowance = 25% of Basic Pay
House Rent Allowance = 15% of Basic Pay
Travelling Allowance = 15% of Basic Pay
Provident Fund = 12% of Basic Pay
Net Pay =
Basic Pay + D.A. + H.R.A + T.A.
Gross Pay = Net Pay - P.F.
So, without further delay, let's begin the tutorial.
Table Of Contents 👊
Go Program To Calculate Employee Salary
// Go Program To Calculate Salary of an Employee
package main
import "fmt"
func main(){
var basePay, da, ta, hra, pf, Salary, gross_pay float64
// Asking for Input
fmt.Print("Enter Base Pay: ")
fmt.Scan(&basePay)
da = (basePay * 0.25)
hra = (basePay * 0.15)
ta = (basePay * 0.15)
pf = (basePay * 0.12)
Salary = (da + hra + ta + basePay)
gross_pay = (Salary - pf)
// Display Output
fmt.Println("S A L A R Y D E T A I L S")
fmt.Println("= = = == = = = == = = = = = = = = = =")
fmt.Println("Base Pay :", basePay)
fmt.Println("Dearness Allowance :", da)
fmt.Println("Travelling Allowance :", ta)
fmt.Println("House Rent Allowance :", hra)
fmt.Println("= = = == = = = == = = = = = = = = = =")
fmt.Println("Net Salary :", Salary)
fmt.Println("Provident Fund :", pf)
fmt.Println("= = = == = = = == = = = = = = = = = =")
fmt.Println("The Gross Salary of the employee is", gross_pay)
}
Output
S A L A R Y D E T A I L S
= = = == = = = == = = = = = = = = = =
Base Pay : 50000
Dearness Allowance : 12500
Travelling Allowance : 7500
House Rent Allowance : 7500
= = = == = = = == = = = = = = = = = =
Net Salary : 77500
Provident Fund : 6000
= = = == = = = == = = = = = = = = = =
The Gross Salary of the employee is 71500
How Does This Program Work ?
var basePay, da, ta, hra, pf, Salary, gross_pay float64
In this program, we have declared float data type variables correspondence to basic pay and their perks.
// Asking for Input
fmt.Print("Enter Base Pay: ")
fmt.Scan(&basePay)
Now, the user is asked to enter the value of basic pay. This value will get stored in basePay named variable.
Salary = (da + hra + ta + basePay)
gross_pay = (Salary - pf)
Then, the salary is calculating by adding all the perks plus basic pay. And Gross Pay is calculated using subtracting provident fund from the salary.
Some of the used terms in this program are as follows:-
package main - packages are a collection of Go source files that reside in the same directory. The line package main specifies that this file belongs to the main package.
Every Executable Go Application must contain the main function.
fmt.Println() - The fmt.Println() function in Go language is used to display output.
fmt.Scan() - The fmt.Scan() function is used to take input from the user in Go Programming language.
:= - The := syntax is shorthand for declaring and initializing a variable.
// - Used for Commenting in Go
Conclusion
I hope after reading this post, you understood how to calculate salary of an employee using Go Programming language.
If you have any doubt regarding the topic, let us know in the comment section.