Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package main
- import "fmt"
- func main() {
- var budget, price, totalSum float64
- fmt.Scanln(&budget)
- counter := 0
- var product string
- fmt.Scanln(&product)
- for product != "Stop" {
- fmt.Scanln(&price)
- counter++
- if counter % 3 == 0 {
- price /= 2
- }
- totalSum += price
- if budget < totalSum {
- break
- }
- fmt.Scanln(&product)
- }
- if product == "Stop" {
- fmt.Printf("You bought %d products for %.2f leva.\n", counter, totalSum)
- } else {
- fmt.Printf("You don't have enough money!\nYou need %.2f leva!\n", totalSum - budget)
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement