Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package main
- import "fmt"
- func main() {
- var neededMoney, budget, money float64
- fmt.Scanln(&neededMoney)
- fmt.Scanln(&budget)
- var input string
- var spendDays = 0
- var saveDays = 0
- for ; budget < neededMoney && spendDays < 5; {
- fmt.Scanln(&input)
- fmt.Scanln(&money)
- if input == "spend" {
- spendDays++
- if money >= budget {
- budget = 0
- } else {
- budget -= money
- }
- } else {
- budget += money
- spendDays = 0
- }
- saveDays++
- }
- if budget < neededMoney {
- fmt.Printf("You can't save the money.\n%d\n", saveDays)
- } else {
- fmt.Printf("You saved the money for %d days.", saveDays)
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement