### Ignoring a value with a while statement I am working on an assignment that revolves around calculating the average boxes a seller sells.

My main question is is that starting in line 22, if the value inputted is a negative (not -1) then it is counted as a seller and becomes part of the final answer. How would i code it so that it ignores a value like -10 with a
'while' statement? If you can include your logic with that too, that'd be most appreciated!

Thank you!

 ``1234567891011121314151617181920212223242526272829303132333435363738394041424344`` ``````#include #include using namespace std; int main() { int numBoxes; // Number of boxes of cookies sold by one child double totalBoxes, // Accumulates total boxes sold by the entire troop numSeller; // Counts the number of children selling cookies double averageBoxes; // Average number of boxes sold per child totalBoxes = 0; numSeller = 1; cout << " **** Cookie Sales Information **** \n\n"; // Get the first input cout << "Enter number of boxes of cookies sold by seller " << numSeller << " (or -1 to quit): "; cin >> numBoxes; while (numBoxes != -1) { totalBoxes += numBoxes; ++numSeller; cout << "\nEnter number of boxes of cookies sold by seller " << numSeller << " (or -1 to quit): "; cin >> numBoxes; } numSeller--; if (numSeller == 0) cout << "\nNo boxes were sold.\n"; else { averageBoxes = totalBoxes / numSeller; cout << "\nThere were " << numSeller << " sellers and they sold an average of " << fixed << setprecision(1) << averageBoxes << " each.\n"; } return 0; }`````` You can do
 ``1234567`` ``````while (numBoxes != -1) { if (numBoxes >= 0) { // do your normal stuff } }``````
or
 ``123456789`` ``````while (numBoxes != -1) { if (numBoxes < 0) { continue; } // do your normal stuff }``````
Last edited on While that would be correct, my assignment does ask for "appropriate while statements". And although I could be going down with a bad case of Occoms Razer, is there a way to use a 'while' statement for this?
Topic archived. No new replies allowed.