Hi,

Your code crashes becoz of line ..

car * car_array = new car[(car_num - 1)];
Say for example..
car_num =4.
In your case memory will be allocated only for 3 objects.Hence the program crashes.


Modify it as

car * car_array = new car[(car_num )];