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?

Header
1
2
3
4
5
6
7
8
9
10
11
12
13
//Mailhouse header

#include <string>

using namespace std;

//Product Definition

	int prod1Count = 0;
	int prod2Count = 0;
	int prod3Count = 0;
	int prod4Count = 0;
	int prod5Count = 0;


Body
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
78
79
#include <iostream>
#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
			<<endl;
	};
@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.