What's wrong with my countValues function? I keep getting 1 failed because of header functions and const int problems?

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
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
* Comments       /10 points
 *
 *
 *  U10_Arrays03.cpp
 *
 * CIS 276 Introduction to C/C++ Programming
 * Chuck Nelson, Professor
 *
 * Student Information (please complete ? below)
 *    Name:         Elizabeth Stevens
 *    RVC Email:    s0340509@student.rockvalleycollege.edu
 * Class Information
 *    Section:      D010
 * Assignment Information
 *                  U10_Arrays03.cpp
 *
 * Purpose: 1D array practice exercises
 * NOTE: this is often thought to be the most difficult of the five.
 
 * Sample Output:

*** start of 27610_Arrays03.cpp program ***

Number    Count
   1        1
   2        2
   3        5
   4        2
   5        3

*** end of 27610_Arrays03.cpp program ***

Input:
   No data comes from the keyboard; all data, including the data
   for the array, are contained within the program.

   An integer array of 13 numbers: 3, 4, 5, 3, 2, 1, 3, 4, 5, 3, 2, 3, 5
   An integer array of 5 counts intialized to all 0.
   Compile-time arrays with initialization list of numbers.
   NOTE: In main() function

Processing:
   TODO #1: in the main() function,
            complete the coding of the numbers array

   TODO #2: in the main() funciton,
            complete the coding to call the countValues() function
            The values in the numbers array are counted
            and the correct cells of the count array are increment.
Output:
   TODO #3: in the main() funciton,
            complete the coding to call the display() function,
               Display as shown in sample output.
               Use iomanipulators to format output

After the main() function
   TODO #4: code the display() function
   TODO #5: code the countValues() function

*/


#include <iostream>
#include <iomanip>
using namespace std;

int main(void)
{
   /* declarations ------------------------------------------------*/
   
   // constants
   const int VALUES_SIZE = 13;
   const int COUNT_SIZE = 5;

   // function prototype(s)
   // return by value is used
   void countValues(const int numbers[], const int VALUES_SIZE, const int counts[]);
   void display(const int counts[], const int COUNT_SIZE);

   // local data

   // data declaration(s) & initialization(s)
   // array data: use data from sample output above
   
   // TODO #1: declare & initialize array of ten integers
   //   replace ?? with the correct initialization list
   // STUDENT CODE BEGINS


   int numbers[VALUES_SIZE] = {3, 4, 5, 3, 2, 1, 3, 4, 5, 3, 2, 3, 5};

   string choice;

   // STUDENT CODE ENDS    

    
    int counts[COUNT_SIZE] = {0};


   /* statements   ------------------------------------------------*/

   // start the program
   cout << "*** start of 276Arrays_03.cpp program ***" << endl;
   cout << endl;


   // TODO #2 : call countValues() function
   //  passing numbers array, array size, counts array
   //   replace the three underlines with the correct parameters
   // STUDENT CODE BEGINS


   countValues(numbers, VALUES_SIZE,counts);



   // STUDENT CODE ENDS




   // TODO #3: call display function,
   //  passing count array & size
   //   replace the two underlines with the correct parameters
   // STUDENT CODE BEGINS


   display( counts, COUNT_SIZE);



   // STUDENT CODE ENDS


    // terminate the program
    cout << endl;
    cout << endl;
    cout << "*** end of 276Arrays_03.cpp program ***" << endl << endl;

    cin.get();
    return 0;
}   // end main()

/*--------------------------------------------------------------------//
// Function Name: display()
// Parameters:       counts[]    : const int
//                   COUNT_SIZE  :  const int
//
// Purpose: to display the count array of values
//
// Notes:
//    display column headings using manipulators
//    in a 'for' loop, print the number and count
//--------------------------------------------------------------------//
// TODO #4: code the display function
// Suggested Algorithm (see Sample Output)

      declare local variables (if needed)

      print column headings

      // display one line for each iteration of the for loop
      for each value in the counts array  (use a 'for' loop)
      
         format & print number

         format & print count of number

      end for loop
*/

// STUDENT CODE BEGINS

   
void display(const int counts, const int COUNT_SIZE)

{
   cout << "Number" << COUNT_SIZE << endl;
   cout << "Count" << counts; 
   cout << endl;
}
   



// STUDENT CODE ENDS

/*--------------------------------------------------------------------//
// Function Name: countValues()
// Parameters:       numbers[]   : const int 
//                   VALUES_SIZE : const int
//                   counts[]    : int       (pass by reference)
//
// Return:           void
//
// Purpose: to count of values in the numbers array
//
// Notes:
//    precondition:  numbers array contains values to be counted
//                      contains only the values 1-5
//    postcondition: contains the counts of the values 1-5 in the 
//                      numbers array
// That is, count the number of ones, twos, threes, fours and fives
//    in the numbers array and store the counts in the counts array.
//--------------------------------------------------------------------//
// TODO #5: code the countValues function
// Suggested Algorithm 

      declare local variables (if needed)

      // print one value for each iteration of the for loop
      for each value in the numbers array (use a for loop)
      
         increment the correct counter in the count array
            based upon the value of the item in the numbers array
            (HINT: use an 'if' statement)

      end for loop
      
      NOTE: counts array is returned by reference and therefore
      does not have to be returned via a return statement.
*/

// STUDENT CODE BEGINS

void countValues(const int numbers[], const int VALUES_SIZE,  const int counts[])

{
	if ( numbers == 1 )

		counts == 2;
}

{
	else if ( numbers == 2)

		counts == 2;
}

{ 
	else if ( numbers == 3)

		counts == 5;
}

{

	else if ( numbers == 4 )

		counts = 2;
}
{
	else ( numbers == 5 )

		counts == 3;

}




// STUDENT CODE ENDS

   //*** start of 27610_Arrays03.cpp program ***

   //Number    Count
   //1        1
   //2        2
   //3        5
   //4        2
   //5        3

   //*** end of 27610_Arrays03.cpp program ***
I think that your code shall not be compiled. For example

1
2
3
4
5
6
7
8
9
10
11
12
13
void countValues(const int numbers[], const int VALUES_SIZE,  const int counts[])

{
	if ( numbers == 1 )

		counts == 2;
} // Here is the end of the function

{// and here the compiler shall issue an error
	else if ( numbers == 2)

		counts == 2;
}


Topic archived. No new replies allowed.