Beginner programmer here, I'm working on an assignment where we have to create a structure that accepts user input, and I'm running into an issue where the output of the program is skipping a piece of the user input.
Essentially I have a piece of code that says:
MovieData movie1;
MovieData movie2;
//Get title
cout << "Enter the title of movie 1: ";
getline(cin, movie1.title);
//Get director
cout << "Enter the name of the director 1: ";
getline(cin, movie1.director);
//Get year released
cout << "Enter the year movie 1 was released: ";
cin >> movie1.yearReleased;
//Get running time
cout << "Enter the duration of movie 1 in minutes: ";
cin >> movie1.runningTime;
//Get title 2
cout << "Enter the title of movie 2: ";
getline(cin, movie2.title);
//Get director 2
cout << "Enter the name of the director 2: ";
getline(cin, movie2.director);
//Get year released 2
cout << "Enter the year movie 2 was released: ";
cin >> movie2.yearReleased;
//Get running time 2
cout << "Enter the duration of movie 2 in minutes: ";
cin >> movie2.runningTime;
This works fine up until the program asks for the second movie title/director. As soon as I enter the duration of the first movie the program outputs asking for both the title and director for the second movie, so it's skipping over asking for the title and going straight to the director. Here's an example of the output with user input in bold:
Enter the title of movie 1: Test mov
Enter the name of the director 1: Test dir
Enter the year movie 1 was released: 1999
Enter the duration of movie 1 in minutes: 129
Enter the title of movie 2: Enter the name of the director 2:
As you can see I never entered anything for the title of the second movie but it skips that part and asks for the director. I originally had all this code inside a function and was running into the same issue so I rewrote it to the code above, but now I'm running into the same issue but only when asking for the second movie title so now I'm a bit lost since it's all working up until asking for the second structures info
If needed here's the code for the structure as well:
struct MovieData
{
string title, director;
int yearReleased, runningTime;
};