Advertisement
Spocoman

Movie Ratings

Nov 28th, 2021
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.16 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 movieVolume = int.Parse(Console.ReadLine());
  10.             double maxRating = 0;
  11.             double minRating = 10;
  12.             string maxMovie = "";
  13.             string minMovie = "";
  14.             double average = 0;
  15.  
  16.             for (int i = 0; i < movieVolume; i++)
  17.             {
  18.                 string movie = Console.ReadLine();
  19.                 double rating = double.Parse(Console.ReadLine());
  20.                 if (rating > maxRating)
  21.                 {
  22.                     maxMovie = movie;
  23.                     maxRating = rating;
  24.                 }
  25.                 else if (rating < minRating)
  26.                 {
  27.                     minMovie = movie;
  28.                     minRating = rating;
  29.                 }
  30.                 average += rating / movieVolume;
  31.             }
  32.             Console.WriteLine($"{maxMovie} is with highest rating: {maxRating:F1}");
  33.             Console.WriteLine($"{minMovie} is with lowest rating: {minRating:F1}");
  34.             Console.WriteLine($"Average rating: {average:F1}");
  35.         }
  36.     }
  37. }
  38.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement