fork download
  1. #include <iostream>
  2. #include <string>
  3. using namespace std;
  4.  
  5. struct MovieData {
  6. string title;
  7. string director;
  8. int year;
  9. float time; //(in minutes)
  10. };
  11.  
  12. MovieData createMovie();
  13. void showMovie(MovieData tempMovie);
  14.  
  15. int main() {
  16. MovieData goodWillHunting = {"Good Will Hunting", "Gus Van Sant", 1997, 1.45};
  17.  
  18. cout << "Movie list" << endl;
  19. showMovie(goodWillHunting);
  20. MovieData secondMovie = createMovie();
  21. showMovie(secondMovie);
  22.  
  23. return 0;
  24. }
  25.  
  26. MovieData createMovie() {
  27. MovieData tempMovie;
  28. getline(cin, tempMovie.title);
  29. getline(cin, tempMovie.director);
  30. cin >> tempMovie.year;
  31. cin >> tempMovie.time;
  32. cin.ignore(); // Clear the newline character from the input buffer
  33. return tempMovie;
  34. }
  35.  
  36. void showMovie(MovieData tempMovie) {
  37. cout << "Title: " << tempMovie.title << endl;
  38. cout << "Director: " << tempMovie.director << endl;
  39. cout << "Year Released: " << tempMovie.year << endl;
  40. cout << "Running Time: " << tempMovie.time << " hours." << endl;
  41. }
  42.  
Success #stdin #stdout 0s 5292KB
stdin
Avengers
Joss Wedon
2012
2.16
stdout
Movie list
Title: Good Will Hunting
Director: Gus Van Sant
Year Released: 1997
Running Time: 1.45 hours.
Title: Avengers
Director: Joss Wedon
Year Released: 2012
Running Time: 2.16 hours.