needing some help on how to find the average number of boxes of cookies sold by children using a counter, accumulator, and an end sentinel (basic programming hwk, yay!). I'm having an issue with figuring out why the averageBoxes prints out the wrong number.
For example:
Program result prints out -5 averageBoxes when that's clearly not right...
{
int numBoxes,
// Number of boxes of cookies sold by one child
totalBoxes = 0, // Accumulates total boxes sold by the entire troop
numSeller = 1; // Counts the number of children selling cookies
double averageBoxes; // Average number of boxes sold per child
// Write code to initialize the totalBoxes accumulator to O and
// The numSeller counter to 1.
cout << "**** Cookie Sales Information ****\n";
// Get the first input
cout << "Enter number of boxes of cookies sold by seller " << numSeller
<< " (or -1 to quit): ";
cin >> numBoxes;
// Write code to start a while loop that loops while numBoxes
// is not equal to -1, the sentinel value.
while(numBoxes != -1)
{
// Write code to add numBoxes to the totalBoxes accumlator.
// Write code to add 1 to the numSeller counter.
totalBoxes += numBoxes;
numSeller++;
// Write code to prompt for and input the number of boxes
// sold by the next seller.
cout << "Enter the number of boxes sold by girl scout # " << numSeller << ": ";
cin >> numBoxes;
}
// When the loop is exited, the value stored in the numSeller counter
// will be one more than the actual number of sellers. So write code
// to adjust it to the actual number of sellers.
numSeller = numSeller - 1;
if(numSeller == 0) // If true, -1 was the very first entry
cout << "\nNo boxes were sold.\n";
else
{ // Write code to assign averageBoxes the computed average number
// of boxes sold per seller.
// Write code to print out the number of sellers and average number
// of boxes sold per seller.
averageBoxes += numSeller / numBoxes;
cout << "The average number of boxes sold by the " << numSeller << " sellers was " << averageBoxes << endl;
}
return 0;
}
It's probably an easy fix but any help would be appreciated, thanks!