lundi 8 mars 2021

Do while loop wont loop?

im writing a do-while loop for school, and no matter where I put the break or remove it either loops infinitely or will not loop, how would I fix this?

do {
failFlag = false;
cout<<"How many crates will be sent?\n";
cin >> iterationNum;
cout<<"\n";
if(cin.fail()){ 
     cin.clear();
     cin.ignore(100, '\n');
     cout << "Enter a number please, how many crates will be sent?\n"; 
     cout<<"\n";
     failFlag = true;
}     
else  
{
    cin>>iterationNum;
}

} while(cin.fail()); // this begins the loop for even output

Aucun commentaire:

Enregistrer un commentaire