Advertisement
Spocoman

Food for Pets

Oct 9th, 2024 (edited)
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Go 0.97 KB | None | 0 0
  1. package main
  2.  
  3. import (
  4.   "fmt"
  5.   "math"
  6. )
  7.  
  8. func main() {
  9.     var days, dailyDogFood, dailyCatFood, eatenDogsFood, eatenCatsFood int
  10.     fmt.Scanln(&days)
  11.    
  12.     var availableFood, cookies float64
  13.     fmt.Scanln(&availableFood)
  14.  
  15.     for i := 1; i <= days; i++ {
  16.         fmt.Scanln(&dailyDogFood)
  17.         fmt.Scanln(&dailyCatFood)
  18.  
  19.         if i % 3 == 0 {
  20.             cookies += float64(dailyDogFood + dailyCatFood) * 0.1
  21.         }
  22.         eatenDogsFood += dailyDogFood
  23.         eatenCatsFood += dailyCatFood
  24.     }
  25.  
  26.     totalEatenFood := eatenDogsFood + eatenCatsFood
  27.  
  28.     fmt.Printf("Total eaten biscuits: %dgr.\n", int(math.Round(cookies)))
  29.     fmt.Printf("%.2f%% of the food has been eaten.\n", float64(totalEatenFood) / float64(availableFood) * 100)
  30.     fmt.Printf("%.2f%% eaten from the dog.\n", float64(eatenDogsFood) / float64(totalEatenFood) * 100)
  31.     fmt.Printf("%.2f%% eaten from the cat.\n", float64(eatenCatsFood) / float64(totalEatenFood) * 100)
  32. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement