Advertisement
Spocoman

06. Cake

Sep 22nd, 2024
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Go 0.57 KB | None | 0 0
  1. package main
  2.  
  3. import (
  4.     "fmt"
  5.     "strconv"
  6. )
  7.  
  8. func main() {
  9.     var x, y, eatenPieces int
  10.     fmt.Scanln(&x)
  11.     fmt.Scanln(&y)
  12.    
  13.     var cakePieces = x * y
  14.  
  15.     var input string
  16.     fmt.Scanln(&input)
  17.  
  18.     for cakePieces > 0 && input != "STOP" {
  19.         eatenPieces,_ = strconv.Atoi(input)
  20.         cakePieces -= eatenPieces
  21.         fmt.Scanln(&input)
  22.     }
  23.  
  24.     if cakePieces >= 0 {
  25.         fmt.Printf("%d pieces are left.\n", cakePieces)
  26.     } else {
  27.         fmt.Printf("No more cake left! You need %d pieces more.\n", cakePieces * -1)
  28.     }
  29. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement