Counting trains by type code A train operator has decided to hire an observer to track the
  different types of trains transiting at a major train platform in
  Europe. Write a program, using a for loop, to track the different
  train types at the major train station. 
  
  The different types of trains are shown in the following table:
  
  

Train types | Train code

Inter-city  | 23            
Regional    | 51        
Overnight   | 72            

  
  The program should ask the user to enter five sets of train codes. 
  
  The program should then count the number of train codes entered and
  display the statistics. 
  
  Sample run

Enter train type #1: 23
Enter train type #2: 23
Enter train type #3: 51
Enter train type #4: 72
Enter train type #5: 23

  
  Sample output

Statistics:
3 Inter-city trains
1 Regional train
1 Overnight train



Can you please check whether this code is correct, and maybe make it shorter?



#include &lt;iostream&gt;
using namespace std;

int main()
{
    int train;
    int InterCity = 0;
    int Regional = 0;
    int Overnight = 0;

    cout &lt;&lt; "          ------Trains------" &lt;&lt; endl;
    for (int i = 1; i &lt;= 5; i++)
    {
        cout &lt;&lt; "Enter train type #" &lt;&lt; i &lt;&lt; ": ";
        cin &gt;&gt; train;

        if (train == 23)
        {
            InterCity++;
        }
        else if (train == 51)
        {
            Regional++;
        }
        else if (train == 72)
        {
            Overnight++;
        }
    }
    cout &lt;&lt; "\n        ------Statistics------" &lt;&lt; endl;
    cout &lt;&lt; InterCity  &lt;&lt; " InterCity trains." &lt;&lt; endl;
    cout &lt;&lt; Regional &lt;&lt; " Regional trains." &lt;&lt; endl;
    cout &lt;&lt; Overnight &lt;&lt; " Overnight trains." &lt;&lt; endl;

    return 0;
}
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
}