Advertisement
Spocoman

Beer and chips

Oct 2nd, 2024
47
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Go 0.58 KB | None | 0 0
  1. package main
  2.  
  3. import (
  4.   "fmt"
  5.   "math"
  6. )
  7.  
  8. func main() {
  9.     var name string
  10.     fmt.Scanln(&name)
  11.  
  12.     var budget float64
  13.     fmt.Scanln(&budget)
  14.    
  15.     var beers, chips int
  16.     fmt.Scanln(&beers)
  17.     fmt.Scanln(&chips)
  18.    
  19.     beerPrice := float64(beers) * 1.20
  20.     chipsPrice := float64(chips) * beerPrice * 0.45
  21.     sum := beerPrice + math.Ceil(chipsPrice)
  22.  
  23.     if budget < sum {
  24.         fmt.Printf("%s needs %.2f more leva!\n", name, sum - budget)
  25.     } else {
  26.         fmt.Printf("%s bought a snack and has %.2f leva left.\n", name, budget - sum)
  27.     }
  28. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement