Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package main
- import "fmt"
- func main() {
- var cargoCount int
- fmt.Scanln(&cargoCount)
- var bus = 0.0
- var truck = 0.0
- var train = 0.0
- var totalCargo = 0.0
- var cargo float64
- for i := 0; i < cargoCount; i++ {
- fmt.Scanln(&cargo)
- if cargo < 4 {
- bus += cargo
- } else if cargo < 12 {
- truck += cargo
- } else {
- train += cargo
- }
- totalCargo += cargo
- }
- var average = (bus * 200 + truck * 175 + train * 120) / totalCargo
- fmt.Printf("%.2f\n", average)
- fmt.Printf("%.2f%%\n", bus / totalCargo * 100)
- fmt.Printf("%.2f%%\n", truck / totalCargo * 100)
- fmt.Printf("%.2f%%\n", train / totalCargo * 100)
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement