循环时我如何摆脱困境



我已经创建了LinkedList,我正在尝试为其中一个修改用户。到目前为止,while循环在课程ID中搜索一个,然后如果发现用户将要求编辑。但是它要求用户两次编辑的问题。

我尝试在if语句甚至exit(0)下使用"断路",但它不起作用。当if语句被执行后,它应该让我保持两次循环。

template <typename T> node<T>* ModifyByCourseId(node<T> *front, string className, string courseId)
{
    node<T> *curr = front;
    while (curr != NULL)
    {
        if (curr->classId == courseId) {
            cout << curr->classId << " " << curr->classDescrip << "." << curr->credit << ":" << curr->creditHr 
                 << curr->Prerequiste << ":" << curr->PreReq << endl; // print the current node's value to the screen
            cout << "Please Modify course title." << endl;          
            getline(cin, curr->classDescrip);
            cout << "Please enter Credit hour(s)." << endl;
            cin >> curr->creditHr;
            cin.ignore(std::numeric_limits<std::streamsize>::max(), 'n');
            cout << "Please enter class pre-requisite(s) if there are more than one separate them by a space." << endl;
            getline(cin, curr->PreReq);
            break;
        }
        curr = curr->next;
    }
    return NULL;
}

我发现了问题。我在语句

中两次调用该函数

最新更新