1

My code keeps skipping part of the instructions and I think it has something to do with getline.

if (userChoice == 'L') {
        userChoice = NULL;
        char option;
        cout << "What are you searching for?" << endl;
        cout << "1. Name" << endl;
        cout << "2. Number" << endl;
        cout << "3. Address" << endl;
        cin >> option;
        while (option != '1' && option != '2' && option != '3') {
            cout << "That was not a valid input. Please try again: " << endl;
            cin >> option;
        }

        if (option == '1') {
            string find;
            cout << "Enter the full name you are looking for: " << endl;
            getline(cin, find);
            bool found = false;
            for (int i = 0; i < a; i++) {
                if (Ptr[i].getName() == find) {
                    found = true;
                    cout << "Entry Found: " << endl;
                    cout << Ptr[i].getName() << endl << Ptr[i].getAddress() << endl << Ptr[i].getNumber() << endl;
                    i = a;
                }
                else if(Ptr[i].getName() != find)
                {
                    i++;
                }
            }
        }

The output prints the initial menu, lets the user input something(1 is the only real option right now) then asks the user to enter the name they are looking for, but immediately after that skips the rest of the if statement and outputs the main menu to the program.

0 Answers0