Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package main
- import (
- "bufio"
- "fmt"
- "os"
- "strconv"
- )
- func main() {
- scanner := bufio.NewScanner(os.Stdin)
- scanner.Scan()
- days,_ := strconv.Atoi(scanner.Text())
- var dayCash, productPrice float64
- var command string
- for i := 0; i < days; i++ {
- dayProducts := 0
- dayCash += 60
- for {
- scanner.Scan()
- command = scanner.Text()
- if command == "Day over" {
- fmt.Printf("Money left from today: %.2f.", dayCash)
- break
- }
- productPrice,_ = strconv.ParseFloat(command, 64)
- if productPrice <= dayCash {
- dayCash -= productPrice
- dayProducts++
- }
- if dayCash == 0 {
- fmt.Print("Daily limit exceeded!")
- break
- }
- }
- fmt.Printf(" You've bought %d products.\n", dayProducts)
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement