Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package main
- import (
- "bufio"
- "fmt"
- "os"
- "strconv"
- )
- func main() {
- var bakers int
- fmt.Scanln(&bakers)
- scanner := bufio.NewScanner(os.Stdin)
- totalSweets := 0
- totalSum := 0.0
- for i := 0; i < bakers; i++ {
- var baker, sweet string
- var cookies, cakes, waffles int
- for {
- scanner.Scan()
- command := scanner.Text()
- if command == "Stop baking!" {
- break
- } else if baker == "" {
- baker = command
- } else {
- sweet = command
- scanner.Scan()
- sweetCount, _ := strconv.Atoi(scanner.Text())
- if sweet == "cookies" {
- cookies += sweetCount
- } else if sweet == "cakes" {
- cakes += sweetCount
- } else {
- waffles += sweetCount
- }
- totalSweets += sweetCount
- }
- }
- totalSum += 1.50 * float64(cookies) + 7.80 * float64(cakes) + 2.30 * float64(waffles)
- fmt.Printf("%s baked %d cookies, %d cakes and %d waffles.\n", baker, cookies, cakes, waffles)
- }
- fmt.Printf("All bakery sold: %d\nTotal sum for charity: %.2f lv.\n", totalSweets, totalSum)
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement