#Why is this getting skipped

17 messages · Page 1 of 1 (latest)

wise ice
#

if u remove a contact then enter 5 ( evoking quit() ) the program terminates but doesn't carryout the function. In my debugger i see that it just never calls quit if called after a RemoveContact. Why?

rancid basaltBOT
#

When your question is answered use !solved to mark the question as resolved.

Remember to ask specific questions, provide necessary details, and reduce your question to its simplest form. For tips on how to ask a good question use !howto ask.

lucid mango
rapid mirage
#

Can you give us a file (or just text) of all of the inputs to your program that would reproduce the issue

#

Not your code's output.
Just your inputs

wise ice
#

this gets skipped ```cpp
void AddressBook::Quit() const{
std::cout << "Thanks for searching!\nGoodbye!\n";
}

#

all of these called in void AddressBook::Run()

rapid mirage
#

Okay now that I know the issue, it's not from removing specifically, just any time you do another command first

wise ice
#

oh yea ur right

rapid mirage
#

looking at this part.
On the GetUserOption line, input gets set to 5.
break jumps to the end of the switch statement.
then the while(input != 5) check is run, and because it is false, the loop end.

        case 4:
            RemoveContact();
            Menu();
            input = GetUserOption();
            break;
        case 5:
            Quit();
            break;
        default:
            break;
        }
    }while(input != 5);
#

Quit() is never even reached

#

anyway, bedtime for me

#

Good luck

wise ice
#

alr tty

wise ice
# rapid mirage Good luck

i added a flag and it now works thank you


void AddressBook::Run(){
    bool flag = true;
    Menu();
    int input = GetUserOption();
    do{
        switch (input)
        {
        case 1:
            ShowAllContacts();
            Menu();
            input = GetUserOption();
            break;
        case 2:
            SearchByName();
            Menu();
            input = GetUserOption();
            break;
        case 3:
            SearchByDepartment();
            Menu();
            input = GetUserOption();
            break;
        case 4:
            RemoveContact();
            Menu();
            input = GetUserOption();
            break;
        case 5:
            Quit();
            flag = false;
            break;
        default:
            break;
        }
    }while(flag);
}
#

!solved