[Solved] C++ : Handling input


There is no need to check the value of d in the while condition if you have the break in each valid case:

while (true) {
        cout << "1.Easy\n";
        cout << "2.Medium\n";
        cout << "3.Hard\n";
        cout << "Choose your difficulty:";
        cin >> d; 
        if (d == '1') {
                a.setdifficulty("Easy");
                break;  
        }       
        else if (d == '2') {
                a.setdifficulty("Medium");
                break;  
        }       
        else if (d == '3') {
                a.setdifficulty("Hard");
                break;  
        }       
        else    
                cout << "Invalid Input!\n";
}

solved C++ : Handling input