### Why Doesn't the Counter Count?

So I'm having issues with the switch. It loops fine and stops when I put in the sentinel value of -1, but when it writes it has 0's for everything...why?

 ``12345678910111213`` ``````//Mailhouse header #include using namespace std; //Product Definition int prod1Count = 0; int prod2Count = 0; int prod3Count = 0; int prod4Count = 0; int prod5Count = 0;``````

Body
 ``12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879`` ``````#include #include "Mailhouseh.h" using namespace std; //labels and values double product1 = 2.98; double product2 = 4.50; double product3 = 9.98; double product4 = 4.49; double product5 = 6.87; double prod1Total; double prod2Total; double prod3Total; double prod4Total; double prod5Total; double completeTotal; int main() { //Switch statements int product = 0; while (product !=-1) {cout << "Enter a number between 1 and 5" << endl; cin >> product; { switch ( product ) { case '1': ++prod1Count; break; case '2': ++prod2Count; break; case '3': ++prod3Count; break; case '4': ++prod4Count; break; case '5': ++prod5Count; break; }//end switch } //Totals per product }//end while //end function inputProduct prod1Total = prod1Count*product1; prod2Total = prod2Count*product2; prod3Total = prod3Count*product3; prod4Total = prod4Count*product4; prod5Total = prod5Count*product5; cout << "\n Product 1:" << prod1Total << "\n Product 2:" << prod2Total << "\n Product 3:" << prod3Total << "\n Product 4:" << prod4Total << "\n Product 5:" << prod5Total <
@lasombrra

Change your `case '1':` to `case '5':` to just plain `case 1:` to `case 5:` You should find that the program works fine afterwards
Whitenite1 you are correct, my book specifically shows the quotes, but you are right it works without it.

Thanks!
@lasombrra

May I ask what book you are using, and what page the example is on? I would like to take a peek through it if I have that volume. I have access to many C++ books, so I may not have actually read the chapter you are referring to. Thanks.
Last edited on
Topic archived. No new replies allowed.