```
// using structures
#include <iostream>
#include <string>
using namespace std;

struct playerinfo
{
    string name;
    int level;
};

int main()
{
    playerinfo arr[5];
    for (int i = 0; i < 5; i++)
    {
        cout << " enter name for player " << i << endl;
        getline(cin, arr[i].name, '\n');
        cout << " and level \n";
        cin >> arr[i].level;
    }
    for (int i = 0; i < 5; i++)
        cout << "the level of player " << arr[i].name << " is " << arr[i].level << endl;
}

```

I am reading a book on c++ syntax and I am practicing. I want the code to behave such that the code asks the user to fill in the names of the players and the levels and then the code prints them all. But it is not behaving like this. when I run the code and enter the name of the player say " tom cat" then the code asks the level and I print an integer say "100", and then unexpected things start happening, the reason of which, I am unable to understand. Can you please help?
edit- few people have asked me to elaborate what "unexpected things" start happening. 
The unexpected thing is that when I type in the name of the player and the level of player 0, the next output on the screen is " enter name for player 1 and level " whereas I expect that it should only output "and level" after I enter the name of the player 1.