Loop if I use a letter and/or a negative number.

Hi guys,

I have a piece a code which I cannot fix:

NEGATIVE_STOCK_PRICE:
cout << "\nPlease enter the desired stock price: " << workCurrency << ends;
cin >> putOption0.S;
if (!(cin >> putOption0.S) || (putOption0.S < 0))
{
cout << "Think you typed in the wrong number please try again" << endl;
cin.clear();
cin.ignore(numeric_limits<streamsize>::max(), '\n');
goto NEGATIVE_STOCK_PRICE;
}

The problem is that I cannot use - if (!(cin >> putOption0.S) || (putOption0.S < 0)) - properly. If I put a negative number, I will need to put it twice. If I use - if (!(putOption0.S) || (putOption0.S < 0)) - my console goes nuts if I use a letter ...

Any advices? =D

Cheers, Oscar.
Either get rid of cin >>putOption0.S; before condition or make first part of the condition if(!(cin) ||.
Last edited on
Topic archived. No new replies allowed.