-3
我已經創建了LinkedList
,我試圖讓用戶修改其中的一個。到目前爲止,while循環搜索一個當然id,然後如果發現用戶將被要求編輯。但問題是它要求用戶兩次編輯。我如何擺脫循環
我試過在if
聲明中使用「break」,甚至是exit(0)
,但它不起作用。在執行if
語句後,它會讓我在while循環中執行兩次。
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;
}
@WasiAhmad爲什麼?使用==是完全一樣的。 –
我不相信'break'不起作用。檢查你是否按下了「if」塊。 –
@WasiAhmad鼓勵誰?你有這個說法的來源嗎? –