Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // You can edit this code!
- // Click here and start typing.
- //https://herz-fuer-tiere.de/haustiere/katzen/katzenjahre-in-menschenjahren-umrechnen#tabelle
- package main
- import "fmt"
- type yearCount struct {
- years int
- months int
- }
- func (yc *yearCount) Add(years, months int) {
- addYrs := years + months/12
- addMonths := months % 12
- yc.years += addYrs
- if yc.months+addMonths > 12 {
- yc.years += 1
- yc.months -= 12
- }
- yc.months += addMonths
- }
- func (yc *yearCount) String() string {
- return fmt.Sprintf("%d year(s) and %d month(s)", yc.years, yc.months)
- }
- func catYears(humanYears float32) float32 {
- if humanYears <= 1.0 {
- return 15.0 * humanYears
- }
- if humanYears <= 2.0 {
- return 15.0 + (10 * (1 - humanYears))
- }
- return 25.0 + (humanYears-2.0)*4
- }
- func catYears2(years, months int) yearCount {
- yc := yearCount{0, 0}
- if years == 0 {
- if months <= 1 {
- yc.Add(0, months*6)
- } else if months <= 3 {
- yc.Add(0, 6+54.0*((months-1)/2.0))
- }
- }
- return yc
- }
- func main() {
- yc := catYears2(0, 2)
- fmt.Println("CatYears:", yc.String())
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement