[英]Phonebook using double Linked List
问题是程序对于第一个选择来说运行良好,但是它开始重复而不要求选择,而是进入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
在循环结束时将choice
设置为0。
然后,代码将检查循环顶部的值。
循环顶部的值为0,不等于3,因此循环继续进行。
如果您仍然想保留“ choice = 0;” 在while循环中,您可以使用类似于以下内容的东西:
如果(选择!= 3)选择= 0;
希望这可以帮助!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.