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

 ``123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254`` ``````* 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 #include 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

 ``12345678910111213`` ``````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.