簡體   English   中英

C ++用戶輸入關閉程序調試

[英]C++ user input closes program debug

我有一個C ++程序,它等待用戶輸入,並且只有在用戶輸入“ q”時才會關閉,並且如果輸入了其他任何內容,則會循環回到菜單。

至少那是應該做的。 程序不會關閉,而不會循環返回。

int main()
{   
    Hierarchy roster;
    char input=' ';
    bool done = false;
    string first, last, full, boss, title;
    while (done != true){
    cout << "Organizational Chart builder, version 0.1" << endl;
    cout << "Please choose your next command: /n";
    cout << "    q   to quit the program " << endl;
    cout << "    a   to add a person " << endl;
    cout << "    c   to count the number of people under someone" << endl;
    cout << "    p   to print the hierarchy " << endl;
    cout << "    r   to remove someone from the hierarchy " << endl;

    cin >> input;

    switch(input)
    {
    case 'q':
        done = true;
        break;
    case 'a':

        cout << "Please enter the person't first name:  ";
        cin >> first;
        cout << "Please enter the person's last name:  ";
        cin >> last;
        cout << "Please enter the person's title";
        cin >> title;
        cout << "Please enter " + first + last +"'s boss. Please enter the full name and title.  If there is none, type none:";
        cin >> boss;
        if (boss == "none")
        roster.insert(full);
        else 
        roster.contains(boss);
        roster.insert(full);
        break;

    case'c':

        cout << "Enter the first name of the person you are searching for:   ";
        cin >> first;
        cout << "Enter the last name:  ";
        cin >> last;
        cout << "What is the person's title:";
        cin >> title;
        full = first + " " + last + " " + title;
        roster.contains(full);
        roster.countb(full);
        break;

    case 'p':
        roster.print();
        break;

    case 'r':

        cout << "Please enter the first, last, and title of the person you want removed:  ";
        cin >> full;
        roster.removeNode(full);
        break;

    }
  }
cout << "Program closed.  " << endl;
return 0;
    }

編輯:現在就可以工作了。 謝謝

您的return語句在while循環中。 拿出來,你應該沒事。

即。 return 0;}} -> } return 0;}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM