OK, so I am creating a program to go along with a lesson from a book C++: A Dialog. So anyway, the program is supposed to get a variable number of pumpkin weights, sort them, and rank them based on which one is heavier. I know the way I am doing it is not efficeint at all, as I sort it in ascending order and then read it backwards, but that is not my problem. The problem is, in the following loop, if I enter anything but a number, then it repeats the loop endlessely, not letting the user input a value... can anyone tell me why this is?
[code=cpp]
while(currentpu mpkin!=0)
{
cout << "Enter pumpkin weight (0 to end): ";
cin >> currentpumpkin;
if(currentpumpk in!=0)
pumpkin.push_ba ck(currentpumpk in);
}
[/code]
[code=cpp]
while(currentpu mpkin!=0)
{
cout << "Enter pumpkin weight (0 to end): ";
cin >> currentpumpkin;
if(currentpumpk in!=0)
pumpkin.push_ba ck(currentpumpk in);
}
[/code]
Comment