Advertisement
Spocoman

Beer Stock

Oct 3rd, 2024
43
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Go 1.06 KB | None | 0 0
  1. package main
  2.  
  3. import (
  4.     "fmt"
  5.   "math"
  6.   "strconv"
  7. )
  8.  
  9. func main() {
  10.     var neededBeers, deliveredBeers int64
  11.     fmt.Scanln(&neededBeers)
  12.    
  13.     var input1, input2 string
  14.     fmt.Scan(&input1)
  15.     fmt.Scan(&input2)
  16.  
  17.     for (input1 + " " + input2) != "Exam Over" {
  18.         amount, _ := strconv.ParseInt(input1, 10, 64)
  19.         beerPackage := input2
  20.         if beerPackage == "sixpacks" {
  21.             amount *= 6
  22.         } else if beerPackage == "cases" {
  23.             amount *= 24;
  24.         }
  25.         deliveredBeers += amount
  26.         fmt.Scan(&input1)
  27.         fmt.Scan(&input2)
  28.     }
  29.  
  30.     deliveredBeers -= deliveredBeers / 100
  31.     diff := int64(math.Abs(float64(neededBeers - deliveredBeers)))
  32.     cases := diff / 24
  33.     sixpacks := diff % 24 / 6
  34.     beers := diff % 6
  35.  
  36.     if deliveredBeers >= neededBeers {
  37.         fmt.Printf("Cheers! Beer left: %d cases, %d sixpacks and %d beers.", cases, sixpacks, beers);
  38.     } else {
  39.         fmt.Printf("Not enough beer. Beer needed: %d cases, %d sixpacks and %d beers.", cases, sixpacks, beers);
  40.     }
  41. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement