My problem is when the user enters a decimal value for the quantity of one of the items, the program ends automatically. What I need it to do, on the other hand, is to display a message letting the user know that they made a mistake and give them the option to try again.
I've tried using the cin.fail() function with no luck whatsoever.
cout<< "\nEnter number of Whizbangs: ";
cin>> WhizbangsAmt;
//This screens out all the negative numbers
while(true)
{
if(WhizbangsAmt < 0)
{
cout<< "Number is negative!\n";
cout<< "Enter number of Whizbangs: ";
cin>> WhizbangsAmt;
}
else
{
break;
}
}
Aucun commentaire:
Enregistrer un commentaire