sets and function

First off this is a homework assignment, just to let everyone know but I am stuck and need help and my teacher isn't answering my emails. So here we go, I am having some problems with function calls and returning the values I want returned my switchStatementCount should do what my switch statement does but instead i get all 0's when i print everything. I'm not totally sure that I pass the set<string> codes correctly, if someone could help me out there that would be cool.


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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
#include <iostream>
#include <string>
#include <iomanip>
#include <fstream>
#include <sstream>
#include <cstdlib>
#include <set>

using namespace std;

//--------------------------------------------------
//------Function Protoyptes-------------------------
//--------------------------------------------------

void printEverything(int vanillaCodes, int strawberryCodes, int blueberryCodes, int raspberryCodes, int keylimeCodes,
		int mixedberryCodes, int rainbowCodes, int bostoncreampieCodes, int redvelvetcakeCodes, int mangoCodes,
		int vanillaSales, int strawberrySales, int blueberrySales, int raspberrySales, int keylimeSales,
		int mixedberrySales, int rainbowSales, int bostoncreampieSales, int redvelvetcakeSales, int mangoSales, 
		int totalCodes, int totalSales, int numCodes);

void switchStatementCount(set<string> codes, int vanillaCodes, int b, int c, int d, int e, int f, int g, int h, int i, int j);

//--------------------------------------------------
//------------Main Function-------------------------
//--------------------------------------------------

int main() {

	int saleCodesNum = 0;
	int numCodes = 0;	
	int numCodes2 = 0;
	int totalSales = 0;
	int totalCodes = 0;
	
	set<string> codes1;
	set<string> saleCodes1;	
	set<string>::iterator it;	
	set<string>::iterator it2;
	
	string codes;
	string saleCodes;
	
	ifstream codesFile;
	ifstream salesFile;
	
	int breakFromSearch = 0;
        int counter2 =0;
	
//------------------------------------
//--the sales of each type of yogurt--
//------------------------------------
	int vanillaSales = 0;
	int strawberrySales = 0;
	int blueberrySales = 0;
	int raspberrySales = 0;
	int keylimeSales = 0;
	int mixedberrySales = 0;
	int rainbowSales = 0;
	int bostoncreampieSales = 0;
	int redvelvetcakeSales = 0;
	int mangoSales = 0;
	
//---------------------------------------
//--the amount of codes for each yogurt--
//---------------------------------------
	int vanillaCodes = 0;
	int strawberryCodes=0;
	int blueberryCodes=0;
	int raspberryCodes=0;
	int keylimeCodes=0;
	int mixedberryCodes=0;
	int rainbowCodes=0;
	int bostoncreampieCodes=0;
	int redvelvetcakeCodes=0;
	int mangoCodes=0;
	

//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------

//	   switchStatementCount(codes1, vanillaSales, strawberrySales, blueberrySales, raspberrySales, keylimeSales,
//			   mixedberrySales, rainbowSales, bostoncreampieSales, redvelvetcakeSales, mangoSales);
	  for(it=codes1.begin(); it!=codes1.end(); it++)
	   {
		    char z = (*it)[5];
		   switch (z)
		     {
		     case '0':
		       vanillaSales++;
		       break;
		     case '1':
		       strawberrySales++;
		       break;
		     case '2':
		       blueberrySales++;
		       break;
		     case '3':
		       raspberrySales++;
		       break;
		     case '4':
		       keylimeSales++;
		       break;
		     case '5':
		       mixedberrySales++;
		       break;
		     case '6':
		       rainbowSales++;
		       break;
		     case '7':
		       bostoncreampieSales++;
		       break;
		     case '8':
		       redvelvetcakeSales++;
		       break;
		     case '9':
		       mangoSales++;
		       break;
		     default:
		       cout << "No Sale for the code: " << *it  << endl;
		     }
	   
	  } 


	   cout << "Most Popular: " << endl;
	   cout << "Least Popular: " << endl;
	   return 0;
}

//-------------------------------------------------
//-----------Function Definitions------------------
//-------------------------------------------------

void switchStatementCount(set<string> codes1, int vanillaSales, int b, int c, int d, int e, int f, int g, int h, int i, int j){
	set<string>::iterator it;
	   for(it=codes1.begin(); it!=codes1.end(); it++)
	 {
	    char z = (*it)[5];
		switch (z)
		     {
		     case '0':
		       vanillaSales++;
		       break;
		     case '1':
		       b++;
		       break;
		     case '2':
		       c++;
		       break;
		     case '3':
		       d++;
		       break;
		     case '4':
		       e++;
		       break;
		     case '5':
		       f++;
		       break;
		     case '6':
		       g++;
		       break;
		     case '7':
		       h++;
		       break;
		     case '8':
		       i++;
		       break;
		     case '9':
		       j++;
		       break;
		     default:
		       cout << "No Sale for the code" <<  endl;
		     }
	 }
}

Last edited on
The way you pass your variables into switchStatementCount just copies them. You need to use references. see http://www.cplusplus.com/doc/tutorial/functions2/
Topic archived. No new replies allowed.