key calculations are not happening...

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.




1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
    // 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>
using namespace 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;
	  }
	  
	  else if (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;
}
Last edited on
1
2
// 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;
I see no such thing in your example output.
this did the trick....code updated above.

Thanks
Mike

Topic archived. No new replies allowed.