问题是程序对于第一个选择运行良好,但它开始重复而不要求选择并进入 addNode 或 SearchNode 函数
list *newList = new list;
int choice = 0;
while (choice != 3)
{
printf("What would you like to do?\n");
printf("1 - Insert something in the phonebook?\n");
printf("2 - Search something from the phonebook?\n");
printf("3 - Nothing at all\n");
printf("Enter 1 through 5: ");
scanf_s("%d", &choice);
switch (choice) {
case 1:
newList->addNode();
break;
case 2:
newList->searchNode();
break;
default:
printf("\nThank you for using the phonebook\n");
}
choice = 0;
}
最佳答案
在循环结束时将 choice
设置为 0。
然后代码会去检查循环顶部的值。
循环顶部的值为 0,不等于 3,因此循环继续。
关于c++ - 使用双链表的电话簿,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40223401/