1

だから私はユーザー入力を検証し、何らかの理由でyまたはnであることを確認する必要があり、それが私にそれを与えておらず、whileループの本体をスパムしています.

char getCharChoice(string message, char y, char n)
{
char choice;

// Print the message and get the input
cout<<message<< " ";
cin>>choice;
// Check for valid input
while (choice != y || choice != n)
{

    cin.clear(); // reset the input stream
    cin.ignore(5000, '\n'); // take any remaining input off the stream

    // Ask for a choice and read user input
cout << "Not a valid input please: Choose y or n:  ";
    cin >> choice;
}


return choice;
}
4

1 に答える 1