line 32 cin>>y;
does not remove the end of line character from the input stream. Consequently, the call to
cin.getline on
line 34 reads everything left on the line and discards the end of line character. For example, if in response to
cin>>y;
you enter 5, then the 'Enter' key, two characters are inserted into the input stream buffer: '5' and '\n'.
cin>>y;
removes the '5' and stores it in the variable y, but the end of line character '\n' is still in the buffer. The cin.getline call on
line 34 reads and stores everything left on the line up to the '\n' character. The '\n' character is read and discarded. But since there was nothing left on the line except the '\n' character,
kbccstudent[y].name is set to an empty string.
To fix the problem you need to discard the rest of the line left in the input stream buffer following the call to
cin>>y;
. One common way to do that is:
std::cin.ignore( std::numeric_limits< std::streamsize >::max(), '\n' );
Add the above line right after
cin>>y;
or at least before the call to
cin.getline.
You will need to add the line
#include <limits>
up with your other includes.
See
http://cplusplus.com/reference/iostream/istream/ignore/ for information on
ignore().