go:wage_calculator

This commit is contained in:
Logen Kain 2017-09-27 20:17:52 -07:00
parent 5fbb29f613
commit 9fde75355e
2 changed files with 67 additions and 0 deletions

17
go/wage_calculator/TODO Normal file
View File

@ -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

View File

@ -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
}