如何在win32控制台应用程序中显示键盘输入,使用cin获取输入

时间:2014-05-14 21:22:06

标签: c++

我的程序中有一部分表示"请输入[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;
    }
}

0 个答案:

没有答案