From 9fde75355e36b9d57ac5ee6c23970f7e9fa4cc4b Mon Sep 17 00:00:00 2001 From: Logen Kain Date: Wed, 27 Sep 2017 20:17:52 -0700 Subject: [PATCH] go:wage_calculator --- go/wage_calculator/TODO | 17 +++++++++++++ go/wage_calculator/main.go | 50 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 67 insertions(+) create mode 100644 go/wage_calculator/TODO create mode 100644 go/wage_calculator/main.go diff --git a/go/wage_calculator/TODO b/go/wage_calculator/TODO new file mode 100644 index 0000000..ac9a262 --- /dev/null +++ b/go/wage_calculator/TODO @@ -0,0 +1,17 @@ +X User enters a number (hourly pay) +X User enters hours per week + +Ask, and if so, then do it: +User enters a percentage to be taken out (taxes, etc) + +X Program returns + +Hourly pay: (what user entered) +Hours per week: (what user entered) + +X Pay per second: +X Pay per minute: +X Pay per hour: +X Pay per week: +X Average pay per month: +X Pay per year diff --git a/go/wage_calculator/main.go b/go/wage_calculator/main.go new file mode 100644 index 0000000..5c133e1 --- /dev/null +++ b/go/wage_calculator/main.go @@ -0,0 +1,50 @@ +package main + +import ( + "bufio" + "fmt" + "os" + "strconv" +) + +func main() { + + wage, _ := input("Enter an hourly wage? ") + hours, _ := input("Enter total weekly hours: ") + + wage_int, err := strconv.ParseFloat(wage, 10) + if err != nil { + panic(err) + } + + hours_int, err := strconv.ParseFloat(hours, 10) + if err != nil { + fmt.Println("All is lost") + panic(err) + } + + fmt.Println("\nHourly wage: ", wage_int) + fmt.Println("Total number of hours: ", hours_int) + + fmt.Printf("\nDollars earned per second: \n\t %.3f", (wage_int/60)/60) + fmt.Printf("\nDollars earned per minute: \n\t %.3f", (wage_int / 60)) + fmt.Printf("\nDollars earned per hour: \n\t %.3f", wage_int) + fmt.Printf("\nAverage dollars earned per day: \n\t %.3f", (wage_int*hours_int)/7) + fmt.Printf("\nDollars earned per week: \n\t %.3f", (wage_int * hours_int)) + fmt.Printf("\nAverage dollars earned per month: \n\t %.3f", (wage_int*hours_int*52)/12) + fmt.Printf("\nYearly pay: \n\t %.3f \n", (wage_int * hours_int * 52)) + +} + +// END MAIN +func input(s string) (string, error) { + stdin_buf := bufio.NewReader(os.Stdin) + + fmt.Print(s) + + text, err := stdin_buf.ReadString('\n') + if err != nil { + panic(err) + } + return text[:len(text)-1], err +}