Go Program To Calculate Employee Salary

In this post we will know how to calculate salary of an employee using Go Programming language.
4 min read

Hello coders, in this post we will know how to calculate salary of an employee using Go Programming language.

Go Program To Calculate Employee Salary

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.

Sloth Coders is a Learning Platform for Coders, Programmers and Developers to learn from the basics to advance of Coding of different langauges(python, Java, Javascript and many more).

You may like these posts

  • Hello coders, in this post we will know how to count number of digits in an integer using Go Programming language. We will be using for loop to count the num…
  • Hello coders, in this post we will learn how to add two numbers using Go Programming language. We will be using different methods to add two numbers in Go language.&…
  • Hello coders, in this post we are going to solve how to calculate electricity bill using Go Programming language. So, without further delay, let's begin this …
  • Hello coders, in this post we will learn how to calculate cube of a number using Go Programming language. A Cube Number is a number multiplied by itself 3 times. …
  • Hello coders, in this post we will learn how to calculate compound interest using Go Programming language. Compound Interest is the interest calculated based …
  • In this post, we will learn how to write hello world program in Go language. Hello, World! is the first program any coder writes to know the basic syntax of any new …

Post a Comment