Advertisement
Spocoman

Baking Competition

Oct 2nd, 2024
52
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Go 1.03 KB | None | 0 0
  1. package main
  2.  
  3. import (
  4.     "bufio"
  5.     "fmt"
  6.     "os"
  7.     "strconv"
  8. )
  9.  
  10. func main() {
  11.     var bakers int
  12.     fmt.Scanln(&bakers)
  13.  
  14.     scanner := bufio.NewScanner(os.Stdin)
  15.  
  16.     totalSweets := 0
  17.     totalSum := 0.0
  18.  
  19.     for i := 0; i < bakers; i++ {
  20.         var baker, sweet string
  21.         var cookies, cakes, waffles int
  22.         for {
  23.             scanner.Scan()
  24.             command := scanner.Text()
  25.             if command == "Stop baking!" {
  26.                 break
  27.             } else if baker == "" {
  28.                 baker = command
  29.             } else {
  30.                 sweet = command
  31.                 scanner.Scan()
  32.                 sweetCount, _ := strconv.Atoi(scanner.Text())
  33.                 if sweet == "cookies" {
  34.                     cookies += sweetCount
  35.                 } else if sweet == "cakes" {
  36.                     cakes += sweetCount
  37.                 } else {
  38.                     waffles += sweetCount
  39.                 }
  40.                 totalSweets += sweetCount
  41.             }
  42.         }
  43.         totalSum += 1.50 * float64(cookies) + 7.80 * float64(cakes) + 2.30 * float64(waffles)
  44.         fmt.Printf("%s baked %d cookies, %d cakes and %d waffles.\n", baker, cookies, cakes, waffles)
  45.     }
  46.  
  47.     fmt.Printf("All bakery sold: %d\nTotal sum for charity: %.2f lv.\n", totalSweets, totalSum)
  48. }
  49.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement