Advertisement
Spocoman

Movie Ratings

Oct 11th, 2024
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Go 0.96 KB | None | 0 0
  1. package main
  2.  
  3.  import (
  4.     "bufio"
  5.     "fmt"
  6.     "os"
  7.     "strconv"
  8. )
  9.  
  10. func main() {
  11.     scanner := bufio.NewScanner(os.Stdin)
  12.     scanner.Scan()
  13.     movies,_ := strconv.Atoi(scanner.Text())
  14.    
  15.     var movie, maxMovie, minMovie string
  16.     var rating, maxRating, totalRating float64
  17.     minRating := 10.0
  18.    
  19.     for i := 0; i < movies; i++ {
  20.         scanner.Scan()
  21.         movie = scanner.Text()
  22.    
  23.         scanner.Scan()
  24.         rating,_ = strconv.ParseFloat(scanner.Text(), 64)
  25.  
  26.         if rating > maxRating {
  27.             maxMovie = movie
  28.             maxRating = rating
  29.         }
  30.         if rating < minRating {
  31.             minMovie = movie
  32.             minRating = rating
  33.         }
  34.         totalRating += rating
  35.     }
  36.  
  37.     fmt.Printf("%s is with highest rating: %.1f\n", maxMovie, maxRating)
  38.     fmt.Printf("%s is with lowest rating: %.1f\n", minMovie, minRating)
  39.     fmt.Printf("Average rating: %.1f\n", totalRating / float64(movies))
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement