Advertisement
Spocoman

Tourist Shop

Oct 14th, 2024
251
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Go 0.68 KB | None | 0 0
  1. package main
  2.  
  3. import "fmt"
  4.  
  5. func main() {
  6.     var budget, price, totalSum float64
  7.     fmt.Scanln(&budget)
  8.  
  9.     counter := 0
  10.    
  11.     var product string
  12.     fmt.Scanln(&product)
  13.    
  14.     for product != "Stop" {
  15.         fmt.Scanln(&price)
  16.         counter++
  17.         if counter % 3 == 0 {
  18.             price /= 2
  19.         }
  20.         totalSum += price
  21.         if budget < totalSum {
  22.             break
  23.         }
  24.         fmt.Scanln(&product)
  25.     }
  26.  
  27.     if product == "Stop" {
  28.         fmt.Printf("You bought %d products for %.2f leva.\n", counter, totalSum)
  29.     } else {
  30.         fmt.Printf("You don't have enough money!\nYou need %.2f leva!\n", totalSum - budget)
  31.     }
  32. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement