madeofglass

Untitled

Feb 17th, 2020
130
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 _05.MovieRatings
  4. {
  5.     class MovieRatings
  6.     {
  7.         static void Main(string[] args)
  8.         {
  9.             int numMovies = int.Parse(Console.ReadLine());
  10.  
  11.             double max = double.MinValue;
  12.             double min = double.MaxValue;
  13.  
  14.             string movieMax = "";
  15.             string movieMin = "";
  16.  
  17.  
  18.             double average = 0.0;
  19.  
  20.             for (int i = 1; i <= numMovies; i++)
  21.             {
  22.                 string movieName = Console.ReadLine();
  23.                 double rating = double.Parse(Console.ReadLine());
  24.  
  25.                 if (rating > max)
  26.                 {
  27.                     max = rating;
  28.                     movieMax = movieName;
  29.                     //Console.WriteLine(movieMax);
  30.                 }
  31.  
  32.                 if (rating < min)
  33.                 {
  34.                     min = rating;
  35.                     movieMin = movieName;
  36.                     //Console.WriteLine(movieMin);
  37.                 }
  38.  
  39.                 average += rating;
  40.                 //Console.WriteLine(average / numMovies);
  41.             }
  42.             double avg = average / numMovies;
  43.  
  44.  
  45.             Console.WriteLine($"{movieMax} is with highest rating: {max:f1}");
  46.             Console.WriteLine($"{movieMin} is with lowest rating: {min:f1}");
  47.             Console.WriteLine($"Average rating: {avg:f1}");
  48.         }
  49.     }
  50. }
Advertisement
Add Comment
Please, Sign In to add comment