output is wrong?? please help

i have a vector that is 10 big with different numbers inside it.
i want to go through the veector and add up how many of each number there is.
ie, if there are four 0's and 9 1's then my new vector should start with 4 9 etc.

the output for my code should be:
1 1 3 3 0 2 0 0 0 0
(this means there is one 0, one 1, three 3, three 4 etc)

but i keep getting this:
1 2 3 4 5 6 7 8 9 10

i think i did it correctly but obviously there is an error.
can anyone find it?

code:


#include <iostream>
#include <string>
#include <vector>
using namespace std;

int main() {

int intensityRange = 6;
int cloudSize = 10;

int cloud [] = {0, 3, 3, 2, 1, 5, 2, 3, 5, 2};
vector <int> totalGreyValues;
int k = 0;

for (int i = 0; i < intensityRange; i++) {
for (int j = 0; j < cloudSize; j++) {
if (cloud[j] == i) {
k = k + 1;
cout << " " << k;
totalGreyValues.push_back (k);
}
else
cout << " no match ";
}
//k = 0;
}

cout << endl << endl << totalGreyValues.size();

for (int h = 0; h < totalGreyValues.size(); h ++)
cout << " " << totalGreyValues[h];

// values --> 0 1 2 3 4 5 6 7 8 9
// answer --> 1 1 3 3 0 2 0 0 0 0

return 0;
}


and if there is anything i can take out or improve upon in the code, please let me know.
thanks a million!
Why is k=0 commented out?

Uncomment it and move totalGreyValues.push_back (k); to a line above it but after the closing brace.
thanks!
Topic archived. No new replies allowed.