Counting trains by type code
Use a switch statement.  Add a default condition to show the error message when the entered train type is not matched with any specified train type.

switch (train) {
    case 23: InterCity++; break;
    case 51: Regional++;  break;
    case 72: Overnight++; break;
    default: // TODO: error handling
}