2016-10-24 3 views
0

를 링크하여전화 번호부 더블 목록을

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; 
} 

답변

1

당신은 마지막에 0 choice를 설정 문제는 그 프로그램은 첫 번째 선택을 위해 잘 실행이지만 선택을 요구하고 addNode 명 또는 SearchNode 함수에 가지 않고 반복 시작 루프의
그런 다음 코드는 루프 상단의 값을 확인합니다.
루프 상단의 값은 0이며 3이 아니므로 루프가 계속됩니다.

0

'choice = 0;'을 계속 유지하려는 경우 while 루프에서 이와 비슷한 것을 사용할 수 있습니다 :

if (choice! = 3) choice = 0;

희망이 도움이됩니다.