vendredi 23 décembre 2016

Else statement triggers no matter if the "if" statement is true or false, where is the issue?

I have a class called Test, and its instances are being filled in a vector. This is my method for editing single elements in the vector (Test class in my case). In this particular method no matter what I do with the if-else statements, the else statement triggers every time, what am I doing wrong?

void Test::editTest(vector<Test>& box) {
string edit1, edit2, edit3, option;
cout << "Enter edit1: " << endl;
cin >> edit;
cout << "Enter edit2: " << endl;
cin >> edit2;
cout << "Enter edit3: " << endl;
cin >> edit3;

for (int i = 0; i < box.size(); i++) {
    if (box.at(i).key == edit && box.at(i).nrindex == edit2 && box.at(i).date == edit3) 

        {   
        int m2 = 0;
        system("CLS");
        cout << "\nPick an option:\n";
        showSingle(box, i);

        cout << "1 : K:\n";
        cout << "2 : J:\n";
        cout << "3 : B:\n";
        cout << "4 : D:\n";
        cout << "5 : R:\n";

        cin>>m2;           
        switch (m2) {
            case (1): 
                cout << "New value:\n";
                cin >> option;
                box.at(i).key = option;
                break;

            case (2):
                cout << "New value:\n\n";
                cin >> option;
                box.at(i).jmbg = option;
                break;

            case (3):
                cout << "New value:\n";
                cin >> option;
                box.at(i).nrindex = option;
                break;

            case (4):
                cout << "New value:\n";
                cin >> option;
                box.at(i).date = option;
                break;

            case (5):
                cout << "New value:\n";
                cin >> res;
                box.at(i).setRes(res);
                break;
            }
       }
       else 
       {
        cout << "Invalid Key combination!" << endl;
        loader();
        break;
       }       
  }
}

Aucun commentaire:

Enregistrer un commentaire