Advertisement
Spocoman

02. Report System

Sep 22nd, 2024
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Go 1.12 KB | None | 0 0
  1. package main
  2.  
  3. import (
  4.     "fmt"
  5.     "strconv"
  6. )
  7.  
  8. func main() {
  9.     var neededSum, sumTransaction int
  10.     fmt.Scanln(&neededSum)
  11.  
  12.     var cashSum = 0
  13.     var cardSum = 0
  14.     var cashCount = 0
  15.     var cardCount = 0
  16.  
  17.     var input string
  18.     fmt.Scanln(&input)
  19.  
  20.     for i := 0; neededSum > 0 && input != "End"; i++ {
  21.         sumTransaction, _ = strconv.Atoi(input)
  22.         if i % 2 == 0 && sumTransaction > 0 && sumTransaction <= 100 || i % 2 == 1 && sumTransaction >= 10 {
  23.             fmt.Println("Product sold!")
  24.             neededSum -= sumTransaction
  25.             if i % 2 == 0 {
  26.             cashSum += sumTransaction
  27.             cashCount++
  28.             } else {
  29.                cardSum += sumTransaction
  30.                cardCount++
  31.             }
  32.         } else {
  33.            fmt.Println("Error in transaction!")
  34.         }
  35.         fmt.Scanln(&input)
  36.     }
  37.  
  38.     if input == "End" {
  39.         fmt.Println("Failed to collect required money for charity.")
  40.     } else {
  41.         fmt.Printf("Average CS: %.2f\nAverage CC: %.2f\n", float64(cashSum) / float64(cashCount), float64(cardSum) / float64(cardCount))
  42.     }
  43. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement