Weird Behavior Of My Code .. (Loop Handling)
<p>The for getting Names of the students.. Does not allow me to enter the name for 5th student .. 
Also please check my Selection sort for sorting strings of names .. 
Any comments, suggestions will be appreciated .. !!</p>

<pre><code>#include &lt;iostream&gt;
#include &lt;string&gt;

using namespace std;

struct Student
{
    string name[5];
    int id[5];
};

void data(Student&amp; s, int size)
{
    cout &lt;&lt; "==== Enter Student Roll Numbers ====" &lt;&lt; endl;
    for (int i = 0; i &lt; size; i++)
    {
        cout &lt;&lt; "Roll No: " &lt;&lt; i+1 &lt;&lt; endl;
        cin &gt;&gt; s.id[i];
    }
    cout &lt;&lt; '\n';
    cout &lt;&lt; "==== Enter Student Names ====" &lt;&lt; endl;
    for (int j = 0; j &lt; size; j++)
    {   
        getline(cin, s.name[j], '\n');
        cout &lt;&lt;"name of student: " &lt;&lt; j+1 &lt;&lt; endl;
    }
    cout &lt;&lt; '\n';
}
void display(Student&amp; s, int size)
{
    cout &lt;&lt; "Roll Numbers Are" &lt;&lt; endl;
    for(int i = 0; i &lt; size; i++)
    {
        cout &lt;&lt; s.id[i] &lt;&lt; " || ";
    }
    cout &lt;&lt; '\n';
    for(int j = 0; j&lt;size; j++)
    {
        cout &lt;&lt; s.name[j] &lt;&lt; " || ";
    }
    cout &lt;&lt; '\n';
}

void sort_id(Student&amp; s, int size) // Bubble Sort
{
    int temp;
    for(int i = 1; i &lt; size; i++)
    {
        for(int j = 0; j &lt; size-i; j++)
        {
            if(s.id[j] &gt; s.id[j+1])
            {
                temp = s.id[j];
                s.id[j] = s.id[j+1];
                s.id[j+1] = temp;
            }
        }
    }
}

void sort_name(Student&amp; s, int size) // Selection Sort
{
    string str;
//  cout &lt;&lt; "SORTED NAMES ARE. !!" &lt;&lt; endl;
    for(int i = 0; i &lt; size-1; i++)
    {
    //  str = i;
        for(int j = i+1; j &lt; size; j++)
        {
            if(s.name[j] &lt; s.name[i])
            {
                str = s.name[j];
                s.name[j] = s.name[i];
                s.name[i] = str;
            }
        }
    }

}
int main()
{

    int size = 5;
    Student s;
    data(s, size);
    display(s, size);
    cout &lt;&lt; '\n';
    sort_id(s, size);
    sort_name(s, size);
    display(s, size);
    cout &lt;&lt; endl;
    system("Pause");
    return 0;
}
</code></pre>
