need help with this simple structures program.

im trying to write a program using structures. there will be 2 movies. user will input information, and program will ouput it back.
the problem : it runs fine until it gets to line 26. when you run it, it will simply output

"Enter title of movie."
"Enter genre of movie."
so it pretty much skips the option for the user to input "title of movie" for the 2nd movie.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#include <iostream>
#include<string>
using namespace std;

struct MovieData
{
	string title, genre, director;
	int yearReleased, runningTime;
};//student

int main()
{
	MovieData movie1;
	cout << "Enter title of movie.\n";
	getline(cin, movie1.title);
	cout << "Enter genre of movie.\n";
	getline(cin, movie1.genre);
	cout << "Enter the director of movie.\n";
	getline(cin, movie1.director);
	cout << "Enter the year this movie was released.\n";
	cin >> movie1.yearReleased;
	cout << "Enter the running time of the movie(in minutes).\n";
	cin >> movie1.runningTime;

	MovieData movie2;
	cout << "Enter title of movie.\n";
	getline(cin, movie2.title);
	cout << "Enter genre of movie.\n";
	getline(cin, movie2.genre);
	cout << "Enter the director of movie.\n";
	getline(cin, movie2.director);
	cout << "Enter the year this movie was released.\n";
	cin >> movie2.yearReleased;
	cout << "Enter the running time of the movie(in minutes).\n";
	cin >> movie2.runningTime;

	cout << movie1.title << endl;
	cout << movie1.genre << endl;
	cout << movie1.director<< endl;
	cout << movie1.yearReleased << endl;
	cout << movie1.runningTime<< endl;

	cout << movie2.title << endl;
	cout << movie2.genre << endl;
	cout << movie2.director << endl;
	cout << movie2.yearReleased << endl;
	cout << movie2.runningTime << endl;

	
	system("PAUSE");
	return 0;
}
Last edited on
1
2
3
MovieData movie2;
cin.ignore();
cout << "Enter title of movie.\n";


I finally got it to work. I decided to try using the cin.ignore() , even though i have never used this before. It seems to work now. Thanks guys.
Topic archived. No new replies allowed.