#include <iostream>
#include <vector>
using namespace std;
struct movie {
string title;
int year;
string actor;
double rating;
};
movie newMovie(){
movie m;
cin.ignore(); // clear the line first
cout << "Please enter the title: ";
getline(cin,m.title);
cout << "Please enter an actor(Last, First): ";
getline(cin, m.actor);
cout << "Please enter the year: ";
cin >> m.year;
cout << "Please enter the rating (1-10): ";
cin >> m.rating;
cin.ignore();
return m;
}
void listMovies(vector<movie> &movies){
for (int i = 0; i < movies.size(); i++){
cout << "Title: " << movies[i].title << endl;
cout << "Year: " << movies[i].year << endl;
cout << "Actor: " << movies[i].actor << endl;
cout << "Rating: " << movies[i].rating << endl;
cout << endl;
}
}
int main()
{
vector<movie> movies;
while (true){
cout << "Would you like to (a)dd a movie, (l)ist movies, or (e)xit? ";
char choice;
cin >> choice;
if (choice == 'a'){
movies.push_back(newMovie());
}
else if (choice == 'l'){
listMovies(movies);
}
else break;
}
return 0;
}
Thursday, 30 January 2025
Code Solutions
Subscribe to:
Post Comments (Atom)
This comment has been removed by the author.
ReplyDeleteThanks for sharing these code solutions! They're well-organized and easy to follow—great for learners who need quick, reliable references. It's always helpful to see clean and simple examples like these. Keep up the great work!
ReplyDeleteEpicforce Tech