Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package main
- import (
- "fmt"
- "strconv"
- )
- func main() {
- var neededSum, sumTransaction int
- fmt.Scanln(&neededSum)
- var cashSum = 0
- var cardSum = 0
- var cashCount = 0
- var cardCount = 0
- var input string
- fmt.Scanln(&input)
- for i := 0; neededSum > 0 && input != "End"; i++ {
- sumTransaction, _ = strconv.Atoi(input)
- if i % 2 == 0 && sumTransaction > 0 && sumTransaction <= 100 || i % 2 == 1 && sumTransaction >= 10 {
- fmt.Println("Product sold!")
- neededSum -= sumTransaction
- if i % 2 == 0 {
- cashSum += sumTransaction
- cashCount++
- } else {
- cardSum += sumTransaction
- cardCount++
- }
- } else {
- fmt.Println("Error in transaction!")
- }
- fmt.Scanln(&input)
- }
- if input == "End" {
- fmt.Println("Failed to collect required money for charity.")
- } else {
- fmt.Printf("Average CS: %.2f\nAverage CC: %.2f\n", float64(cashSum) / float64(cashCount), float64(cardSum) / float64(cardCount))
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement