1

There is a portion of my program that says "Please enter [A] or [B]" then uses cin to get input. I want to make it so that "A" or "B" gets removed off the console line after the user presses enter so they don't have to look at it.

Here is the code:

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;
    }
}
Colin Basnett
  • 4,052
  • 2
  • 30
  • 49
0000
  • 677
  • 2
  • 8
  • 20
  • 2
    Not sure this is possible with IO manipulators, if this is for windows then the winapi console functions will allow you to do this, and I'm sure other OSs have similar things. – Matt May 14 '14 at 21:27
  • 2
    You can't do that with `cin` directly, you have to use specific functionality provided by Windows (or whatever OS). There are quite a few different questions on this sort of thing already. Try searching for "cin with no echo". – Mats Petersson May 14 '14 at 21:31
  • Did some research on "cin with no echo" and, well that escalated quickly. You would think they would have a class built into c++ that could handle passwords. This is above and beyond my current skill level, but good to know for the future! – 0000 May 14 '14 at 21:50

0 Answers0