Running into a little trouble with this one. The comments on the code pretty much explain what the program is supposed to do. I'm just brain farting on it. I got it to execute fine, but the key factors it is supposed to do is not happening. I'm missing some things but can't think of it off hand. I thank you for your help in advance.
// This program finds the average number of boxes of cookies
// sold by the children in a particular scout troop.
// It illustrates the use of a counter, an accumulator,
// and an end sentinel.
// Michael McDonald
#include <iostream>
usingnamespace std;
int main()
{
//Variables
int numBoxes, // Number of boxes of cookies sold by one child
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; // WRITE CODE TO INITIALIZE THE totalBoxes ACCUMLATOR TO 0
numSeller = 1; // THE numSeller COUNTER TO 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): " <<endl;
cin >> numBoxes;
// WRITE CODE TO START A while LOOP THAT LOOPS WHILE numBoxes
while (numBoxes)
{
// IS NOT EQUAL TO -1, THE SENTINEL VALUE.
if (numBoxes !=-1)
{
cout << "The total number of boxes sold by seller " << numSeller << "is: " <<numBoxes <<endl;
}
elseif (numBoxes == -1)
{
break;
}
// WRITE CODE TO ADD numBoxes TO THE totalBoxes ACCUMULATOR.
totalBoxes += numBoxes;
// WRITE CODE TO ADD 1 TO THE numSeller COUNTER.
numSeller++;
// WRITE CODE TO PROMPT FOR AND INPUT THE NUMBER OF BOXES SOLD BY THE NEXT SELLER.
cout << "Enter the next seller's number of boxes sold: " << numSeller
<< " (or -1 to quit): " <<endl;
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--;
if (numSeller == 0)
cout << "\nNo boxes were sold.\n";
else
{
averageBoxes = (double)totalBoxes / (double)numSeller;
// 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.
cout << "The total number of sellers is: " << numSeller << "and the average number of boxes sold by each seller is: " << averageBoxes <<endl;
}
system("pause");
return 0;
}
// WRITE CODE TO ADD numBoxes TO THE totalBoxes ACCUMULATOR.
totalBoxes = numBoxes;
that's assignment, is not adding.
1 2
// WRITE CODE TO ADD 1 TO THE numSeller COUNTER.
numSeller = +1;
again, same mistake.
1 2 3
cout << "Enter number of boxes of cookies sold by seller " << numSeller
//...
cout << "The total number of boxes sold by " << numSeller << "is: " <<numBoxes <<endl;