0

I've already run my program properly but when I add switch case error occurs:

[Error] crosses initialization of 'person p_array [size]

I know that error occurs because I initialize person p_array[size] on case 1 because I want size of p_array to resize dynamically to save some space for my program to run

here is my code:

int main()
{
    Program people;
    int size = 0,ch;
    bool exit = false;
    
    cout << "[0] Exit"<<endl;
    cout << "[1] Create List"<<endl;
    cout << "[2] Display"<<endl;
    cout << "Enter: ";
    cin>>ch;
    do
    {
     switch(ch)
     {
        case 0:
             exit = true;
             break;
        case 1:
             cout << "Enter how many people should be on the list?: ";
             cin>>size;
             person p_array[size];
             people.getDetails(p_array,size);
             people.mergeSort(p_array,0,(size-1),size);
             break;
        case 2:
             people.sort_by_category(p_array,size);
             break;
     }
    }while(!exit);

return 0;
}```

0 Answers0