Advertisement
Spocoman

Easter Shop

Oct 8th, 2024
44
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Go 0.71 KB | None | 0 0
  1. package main
  2.  
  3. import "fmt"
  4.  
  5. func main() {
  6.     var availableEggs, eggs, soldEggs  int
  7.     fmt.Scanln(&availableEggs)
  8.    
  9.     var input string
  10.     fmt.Scanln(&input)
  11.  
  12.     for input != "Close" {
  13.         fmt.Scanln(&eggs)
  14.         if input == "Buy" {
  15.             if availableEggs - eggs < 0 {
  16.                 break
  17.             }
  18.             availableEggs -= eggs
  19.             soldEggs += eggs
  20.         } else if input == "Fill" {
  21.             availableEggs += eggs
  22.         }
  23.         fmt.Scanln(&input)
  24.     }
  25.  
  26.     if input == "Close" {
  27.         fmt.Printf("Store is closed!\n%d eggs sold.\n", soldEggs)
  28.     } else {
  29.         fmt.Printf("Not enough eggs in store!\nYou can buy only %d.\n", availableEggs)
  30.     }
  31. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement