mardi 24 mars 2015

While loops forever

Im trying to have the program prompt the user for a valid input after inputting something other than a positive number, but this code just makes it loop forever. How would i get it to ask the user to input a valid input again?



cout << "\tAmount on deposit: ";
cin >> deposit;
if (!deposit || deposit < 0){

while (!deposit || deposit < 0)
{
cout << "\tPlease enter a positive number! " << endl;
cout << setw(60) << "Amount on deposit: ";
cin.ignore(deposit);
}
}else ...

Aucun commentaire:

Enregistrer un commentaire