Hi, there is not much information about what do you need to do, but base on the C++ code you need to complete it to count the number of items in the array, using the instructions already written.
Answer:
#include <iostream>
using namespace std;
int main()
{
int numList [] = {2,3,4,5,6,7,9,11,12,13,14,15,16};
int count=0;
for(int spot=0; spot < (sizeof(numList)/sizeof( numList[ 0 ])); ++spot)
{
cout << numList[spot];
cout << "\n";
++count;
}
cout << "The number of items in the array is: ";
cout << count;
return 0;
}
Explanation:
To complete the program we need to finish the for statement, we want to know the number of items, we can get it by using this expression: (sizeof(numList)/sizeof( numList[ 0 ])), sizeof() function returns the number of bytes occupied by an array, therefore, the division between the number of bytes occupied for all the array (sizeof(numList)) by the number of bytes occupied for one item of the array (sizeof( numList[ 0])) equal the length of the array. While iterating for the array we are increasing the variable count that at the end contains the result that we print using the expression cout << "The number of items in the array is: "