문제

I've tried several things suggested on stackoverflow such as break statements and incrementing a number in addition to the pre-existing condition and have had no success.

This code results in an infinite output after a doctor is selected, REGARDLESS of what is entered when the user is asked if they wish to continue.

void ClinicDriver::OpenQueue()//see comment at bottom
{
bool cont = true;
while (cont == true)
{
    int QueueChoice;
    for (int a = 0; a < 6; a++)
    {
        cout << Doctors[a] << endl;
    }
cout << "Select a Doctor by number." << endl;
cin >> QueueChoice;
status[QueueChoice - 1] = true;
cout << "Do you wish to continue?" << endl;
cin >> cont;
}
}

And this code tells me I've made an access violation and blows up when trying to change part of the array.

void ClinicDriver::OpenQueue()
{
bool cont = true;
int n = 0;
while (cont == true && n < 6)
{
    int QueueChoice;
    for (int a = 0; a < 6; a++)
    {
        cout << Doctors[a] << endl;
    }
cout << "Select a Doctor by number." << endl;
cin >> QueueChoice;
status[QueueChoice - 1] = true;                  //blows up here
cout << "Do you wish to continue?" << endl;
cin >> cont;
n++;
}
}

Any help or advice is greatly appreciated, thanks.

도움이 되었습니까?

해결책

Reading a bool from cin is probably going to evaluate to true every time. Instead, ask the user for a value of "yes" or "no" in a string format, then check which input you receive.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top