I was just trying to test out how arrays structure worked, so I tried to write a code where it asks the information of 2 movies. But somehow my code just skips on the movie 2. Help!?
struct FavMovie
{
string movie;
int year;
};
int main ()
{
const int NUM_MOVIES = 2;
FavMovie movieFav[NUM_MOVIES];
int index;
cout << "Please enter the information of " << NUM_MOVIES
<< " Movies: \n";
for (int index = 0; index < NUM_MOVIES; index++)
{
cout << "Please enter the name of the" << (index + 1);
cout << " movie ";
getline (cin, movieFav[index].movie);
cout << "Please enter the year the " << (index + 1);
cout << " movie came out ";
cin >> movieFav[index].year;
}
for (int index = 0; index < NUM_MOVIES; index++)
{
cout << "The name of the " << index + 1
<< " movie is: " << movieFav[index].movie;
cout << "The year the " << index + 1
<< " movie came out was " << movieFav[index].year;
}
Aucun commentaire:
Enregistrer un commentaire