I'm writing a program to gain info and then print it. Problem is when a person enter $1231 for my account the $ crashes it.

I would like to use cin.peek to check if it is there if it is delete it

so far i have

cout << "Balance : ";
        cin >> file.balance;
            if(file.balance < 0)
            {
                cout << "Please Enter postivie numerical value for balance: ";
                cin >> file.balance;
            }
        if(cin.peek() == '$')
        {
            // get one character
            cin.ignore('$')
        }
        //read the number

Recommended Answers

All 3 Replies

A simple solution.

int balance;

cout << "Balance : ";

if (cin.peek() == '$')
  cin.ignore();

cin >> balance;

Hope this helps :)

Thank you

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.