Advertisement
Spocoman

Trip Expenses

Oct 14th, 2024
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Go 0.97 KB | None | 0 0
  1. package main
  2.  
  3. import (
  4.     "bufio"
  5.     "fmt"
  6.     "os"
  7.     "strconv"
  8. )
  9.  
  10. func main() {
  11.     scanner := bufio.NewScanner(os.Stdin)
  12.     scanner.Scan()
  13.     days,_ := strconv.Atoi(scanner.Text())
  14.    
  15.     var dayCash, productPrice float64
  16.     var command string
  17.  
  18.     for i := 0; i < days; i++ {
  19.         dayProducts := 0
  20.         dayCash += 60
  21.  
  22.         for {
  23.             scanner.Scan()
  24.             command = scanner.Text()
  25.             if command == "Day over" {
  26.                 fmt.Printf("Money left from today: %.2f.", dayCash)
  27.                 break
  28.             }
  29.  
  30.             productPrice,_ = strconv.ParseFloat(command, 64)
  31.             if productPrice <= dayCash {
  32.                 dayCash -= productPrice
  33.                 dayProducts++
  34.             }
  35.  
  36.             if dayCash == 0 {
  37.                 fmt.Print("Daily limit exceeded!")
  38.                 break
  39.             }
  40.         }
  41.  
  42.         fmt.Printf(" You've bought %d products.\n", dayProducts)
  43.     }
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement