Advertisement
sanyakasarova

04. Movie Ratings

Oct 23rd, 2021
622
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.36 KB | None | 0 0
  1. using System;
  2.  
  3. namespace Loops
  4. {
  5.     class Program
  6.     {
  7.         static void Main(string[] args)
  8.         {
  9.             int numOfMovies = int.Parse(Console.ReadLine());
  10.  
  11.             string highestRatedMovie = String.Empty;
  12.             double highestRating = double.MinValue;
  13.  
  14.             string lowestRatedMovie = String.Empty;
  15.             double lowestRating = double.MaxValue;
  16.  
  17.             double ratingSum = 0;
  18.  
  19.             for (int i = 0; i < numOfMovies; i++)
  20.             {
  21.                 string movieName = Console.ReadLine();
  22.                 double rating = double.Parse(Console.ReadLine());
  23.  
  24.                 ratingSum += rating;
  25.  
  26.                 if (rating > highestRating)
  27.                 {
  28.                     highestRating = rating;
  29.                     highestRatedMovie = movieName;
  30.                 }
  31.  
  32.                 if (rating < lowestRating)
  33.                 {
  34.                     lowestRatedMovie = movieName;
  35.                     lowestRating = rating;
  36.                 }
  37.  
  38.             }
  39.  
  40.             double averageRating = ratingSum / numOfMovies;
  41.  
  42.  
  43.             Console.WriteLine($"{highestRatedMovie} is with highest rating: {highestRating:f1}");
  44.             Console.WriteLine($"{lowestRatedMovie} is with lowest rating: {lowestRating:f1}");
  45.             Console.WriteLine($"Average rating: {averageRating:f1}");
  46.         }
  47.     }
  48. }
  49.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement