Advertisement
Spocoman

03. Vacation

Sep 22nd, 2024
32
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Go 0.80 KB | None | 0 0
  1. package main
  2.  
  3. import "fmt"
  4.  
  5. func main() {
  6.     var neededMoney, budget, money float64
  7.     fmt.Scanln(&neededMoney)
  8.     fmt.Scanln(&budget)
  9.    
  10.     var input string
  11.  
  12.     var spendDays = 0
  13.     var saveDays = 0
  14.    
  15.     for ; budget < neededMoney && spendDays < 5; {
  16.         fmt.Scanln(&input)
  17.         fmt.Scanln(&money)
  18.         if input == "spend" {
  19.             spendDays++
  20.             if money >= budget {
  21.                 budget = 0
  22.             } else {
  23.                 budget -= money
  24.             }
  25.         } else {
  26.             budget += money
  27.             spendDays = 0
  28.         }
  29.         saveDays++
  30.     }
  31.  
  32.     if budget < neededMoney {
  33.         fmt.Printf("You can't save the money.\n%d\n", saveDays)
  34.     } else {
  35.         fmt.Printf("You saved the money for %d days.", saveDays)
  36.     }
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement