Advertisement
Spocoman

Movie Ratings

Sep 21st, 2023
484
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.85 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3.  
  4. using namespace std;
  5.  
  6. int main() {
  7.     int movieCount;
  8.     cin >> movieCount;
  9.  
  10.     double rating, maxRating = 0, minRating = 10, totalRating = 0;
  11.     string movie, maxMovie = "", minMovie = "";
  12.  
  13.     for (int i = 0; i < movieCount; i++) {
  14.         cin.ignore();
  15.         getline(cin, movie);
  16.         cin >> rating;
  17.  
  18.         if (rating > maxRating) {
  19.             maxMovie = movie;
  20.             maxRating = rating;
  21.         }
  22.         if (rating < minRating) {
  23.             minMovie = movie;
  24.             minRating = rating;
  25.         }
  26.         totalRating += rating;
  27.     }
  28.  
  29.     printf("%s is with highest rating: %.1f\n", maxMovie.c_str(), maxRating);
  30.     printf("%s is with lowest rating: %.1f\n", minMovie.c_str(), minRating);
  31.     printf("Average rating: %.1f\n", totalRating / movieCount);
  32.  
  33.     return 0;
  34. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement