Advertisement
Spocoman

04. Clever Lily

Sep 20th, 2024
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Go 0.62 KB | None | 0 0
  1. package main
  2.  
  3. import "fmt"
  4.  
  5. func main() {
  6.     var age int
  7.     fmt.Scanln(&age)
  8.    
  9.     var machinePrice, toyPrice float64
  10.     fmt.Scanln(&machinePrice)
  11.     fmt.Scanln(&toyPrice)
  12.  
  13.     var sum = 0.0
  14.     var toy = 0.0
  15.     var birthday = 10.0
  16.  
  17.     for i := 3; i < age + 3; i++ {
  18.         if i % 2 == 0 {
  19.             sum += birthday - 1
  20.             birthday += 10
  21.         } else {
  22.             toy++
  23.         }
  24.     }
  25.  
  26.     sum += toy * toyPrice
  27.  
  28.     if sum >= machinePrice {
  29.         fmt.Printf("Yes! %.2f\n", sum - machinePrice)
  30.     } else {
  31.         fmt.Printf("No! %.2f\n", machinePrice - sum)
  32.     }
  33. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement