Проблема создания меню (невозможно удалить элемент di sh (элемент) после удаления элемента di sh в векторе) - PullRequest
0 голосов
/ 07 марта 2020

У меня возникли проблемы с этой частью моего проекта в моем классе с ++, где мой учитель поручил нам составить меню ди sh. Пользовательский ввод (число) представляет собой целочисленное значение, где, если оно равно 1, оно спросит имя и цену и добавит в меню di sh, а если число равно 2, то будет искать di sh, если это 3, это изменит цену для определенного di sh, а если 4, то удалит определенное di sh. Проблема в том, что после удаления di sh я больше не могу добавлять блюда. спасибо за помощь

if(number==1){
        cin.ignore();
        cout<<"Enter name of dish: ";
        getline(cin,name);
        cout<<endl;
        cout<<"Enter price: ";
        cin>>price;
        cout<<endl;
        if(cin.fail() || price<0){
            cin.clear();
            cin.ignore(256, '\n');
            cout<<"INVALID PRICE"<<endl;
        }
        transform(name.begin(), name.end(), name.begin(), ::tolower); 
        if(price>0){
            if(int(arrNAME.size())>=10){
                cout<<"Menu already has 10 dishes"<<endl;
            }
            else{
                for(int i=0; i<int(arrNAME.size()); i++){
                    if (arrNAME[i]==name){
                        cout<<"already added"<<endl;
                        condition=1;
                    }
                }
                if(condition!=1 && price>=0){
                    arrNAME.push_back(name);
                    arrPRICE.push_back(price);
                    cout<<name<<" "<<"added"<<endl;

                }
            }
        }
    }
    if(number==2){
        cout<<"Enter dish name: ";
        cin.ignore();
        getline(cin, name);
        cout<<endl;
        transform(name.begin(), name.end(), name.begin(), ::tolower); 
        for(int i=0; i<int(arrNAME.size()); i++){
            if(arrNAME[i]==name){
                cout<<"Dish: "<<name<<" "<<"Price: "<<arrPRICE[i]<<" "<<"selected"<<endl;
                condition=1;
            }
        }
        if(condition!=1){
            cout<<name<<"not on menu"<<endl;
        }
    }
    if(number==3){
        cout<<"Enter name of dish: ";
        cin.ignore();
        getline(cin, name);
        cout<<endl;
        cout<<"Enter price: ";
        cin>>price;
        cout<<endl;
        if(cin.fail() || price<0){
            cin.clear();
            cin.ignore(256, '\n');
            cout<<"INVALID INPUT"<<endl;
        }
        if(price>=0){
            transform(name.begin(), name.end(), name.begin(), ::tolower); 
            for(int i=0; i<int(arrNAME.size()); i++){
                if (arrNAME[i]==name) {
                    arrPRICE[i]=price;
                    condition=1;
                    cout<<"Dish price updated"<<endl;
                }
            }
            if (condition!=1){
                cout<<"not on menu"<<endl;
            }
        }
    }
    if(number==4){
        cout<<"enter dish name: ";
        cin.ignore();
        getline(cin, name);
        cout<<endl;
        transform(name.begin(), name.end(), name.begin(), ::tolower); 
        for(int i=0; i<int(arrNAME.size()); i++){
            if (arrNAME[i]==name){
                arrNAME.erase(arrNAME.begin()+i);
                arrPRICE.erase(arrPRICE.begin()+i);
                condition=1;
                cout<<"dish erased"<<endl;
            }
        }
        if(condition!=1){
            cout<<"not on menu"<<endl;
        }
    }
...