SvetlanPetrova

MovieRatings

Apr 8th, 2019
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.44 KB | None | 0 0
  1. using System;
  2.  
  3. namespace MovieRatings
  4. {
  5.     class Program
  6.     {
  7.         static void Main(string[] args)
  8.         {
  9.             int moviesNumber = int.Parse(Console.ReadLine());
  10.  
  11.             double maxRating = double.MinValue;
  12.             double minRating = double.MaxValue;
  13.             double sumRatings = 0;
  14.             int ratingsCount = 0;
  15.             double aveRating = 0;
  16.  
  17.             string maxRatingMovie = string.Empty;
  18.             string minRatingMovie = string.Empty;
  19.  
  20.             for (int i = 1; i <= moviesNumber; i++)
  21.             {
  22.                 string movieName = Console.ReadLine();
  23.                 double movieRating = double.Parse(Console.ReadLine());
  24.                 ratingsCount++;
  25.                 sumRatings += movieRating;
  26.                 aveRating = sumRatings / ratingsCount;
  27.  
  28.                 if (movieRating > maxRating)
  29.                 {
  30.                     maxRating = movieRating;
  31.                     maxRatingMovie = movieName;
  32.                 }
  33.                 if (movieRating < minRating)
  34.                 {
  35.                     minRating = movieRating;
  36.                     minRatingMovie = movieName;
  37.                 }
  38.             }
  39.  
  40.  
  41.             Console.WriteLine($"{maxRatingMovie} is with highest rating: {maxRating:f1}");
  42.             Console.WriteLine($"{minRatingMovie} is with lowest rating: {minRating:f1}");
  43.             Console.WriteLine($"Average rating: {aveRating:f1}");
  44.  
  45.         }
  46.     }
  47. }
Add Comment
Please, Sign In to add comment