Q:

C++ Switch Statement with While Loop

I have a system where user can enter as many inputs as s/he wants and make some calculations. 
Here is the main loop for achieving this task:
int main() {
    char op;

    while(op != 'x'){
        cout << "Please select: " << endl;
        cout << "1 ---> A" << endl;
        cout << "2 ---> B" << endl;
        cout << "3 ---> C " << endl;
        cout << "4 ---> D " << endl;
        cout << "5 ---> Calculate" << endl;
        cout << "x ---> Exit" << endl;

        op = std::getchar();

        switch(op){
        case '1':
            cout<<"1";
            break;
        case '2':
            cout<<"2";
            break;
        case '3':
            cout<<"3";
            break;
        case '4':
            cout<<"4";
            break;
        case '5':
            cout<<"5";
            break;
        case 'x':
            return 0;
        default:
            continue;
        }

    }
    return 0;
}

However, in the console I have seen the cout statements two times instead of one. A sample console looks like this: 
Please select: 
1 ---> A
2 ---> B
3 ---> C 
4 ---> D 
5 ---> Calculate
x ---> Exit
1
1Please select: 
1 ---> A
2 ---> B
3 ---> C 
4 ---> D 
5 ---> Calculate
x ---> Exit
Please select: 
1 ---> A
2 ---> B
3 ---> C 
4 ---> D 
5 ---> Calculate
x ---> Exit

Any ideas on how to display cout statements only once after user makes selection?

A:

It looks like you still have some characters in the input stream after 
    op = std::getchar();

Add a line to ignore the rest of the line from the input stream.
    op = std::getchar();
    int temp;
    while ( (temp = std::getchar()) != '\n' && temp != EOF );

