我的程序中有一部分表示"请输入[A]或[B]" 然后用cin来获取输入。我想让它成为" A"或" B"用户按下Enter后会从控制台行中删除,这样他们就不必查看它了。
以下是代码:
double water(char chrSelection, int numQuant)
{
system("CLS");
cout << "%%%%%%%%%" << endl;
cout << "% Water %" << endl;
cout << "%%%%%%%%%" << endl << endl;
cout << endl << "A.) 12pk;";
cout << endl << "B.) 24pk;" << endl;
cout << "Please enter [A] or [B]" << endl;
cin >> chrSelection;
//cout << '\b' << endl;
chrSelection = toupper(chrSelection);
cout << "Quantity: ";
cin >> numQuant;
if (chrSelection == 'A')
{
return numQuant * 1.49;
}
else if (chrSelection == 'B')
{
return numQuant * 2.49;
}
}