С++. Структуры. Завершает работу после первого ввода
Написал простое задание на тему структур, реализовал с помощью функций, сам код будет ниже. Вызывается 2 функции, создания и печати, если название нужного города совпадает с названием город в n-ной структуре. Без функций все работает нормально, если заносить в функции, то сначала вызывается функция создания(ввода), ввожу поле date(самая первая запись) и программу сразу же завершает работу. Почему так происходит? Сам код:
#include <iostream>
using namespace std;
struct ATC{
string date;
string kod_name;
float duration;
float tarif;
string numbercity;
string number;
};
void createstruct(ATC *A, int n){
for (int i = 0; i<=n;i++) {
cout << "Enter date: "; cin >> A[i].date;
cout << "Enter kod_name: "; cin >> A[i].kod_name;
cout << "Enter duration: "; cin >> A[i].duration;
cout << "Enter tarif: "; cin >> A[i].tarif;
cout << "Enter numbercity: "; cin >> A[i].numbercity;
cout << "Enter number: "; cin >> A[i].number;
}
return;
}
void printstruct(ATC *A, int n, string city){
int count(0);
for (int i = 0; i<=n; i++){
if (A[i].kod_name == city){
count++;
cout << A[i].date << endl << A[i].kod_name << endl << A[i].duration << endl << A[i].tarif << endl << A[i].number << endl << count << endl;
}
}
return;
}
int main()
{
int n;
cout << "Enter record count: "; cin >> n;
struct ATC A[n];
int key;
string city;
cout << "Enter city: "; cin >> city;
createstruct(&A[n], n);
printstruct(&A[n], n, city);
return 0;
}