I'm trying to increment the values in a vector, not the vector size, based on variable input. Basically I have a vector of size 10, and all of its values are initialized at zero. The program counts the frequency of numbers 0-9 in a four digit user input. This is what I have (I want it to work so badly but the compiler says that I'm using a pointer to a function used in arithmetic):
for (int i=0; i < num_slots; ++i) {
++guess_frequency[guess[i]];
}
I just want to know if you can increment values within a vector:
e.g. change
0 0 0 0 0 0 0 0 0 0
to
1 0 0 0 2 0 0 1 0 0
for (int i=0; i < range_top; ++i){ // initialize vector values at 0
guess_frequency.push_back(zero);
solution_frequency.push_back(zero);
}
for (int i=0; i < num_slots; ++i){ // insert values for guess freq.
int x;
x = guess[i];
++guess_frequency[x];
}
for (int i=0; i < num_slots; ++i){ // insert values for solution freq.
int y;
y = solution[i];
++solution_frequency[y];
}
And the errors I get are:
proj3.cc:202:20: warning: pointer to a function used in arithmetic [-Wpointer-arith]
x == guess[i];
^
proj3.cc:202:20: error: ISO C++ forbids comparison between pointer and integer [-fpermissive]
proj3.cc:208:23: warning: pointer to a function used in arithmetic [-Wpointer-arith]
y == solution[i];
^
proj3.cc:208:23: error: ISO C++ forbids comparison between pointer and integer [-fpermissive]
make: *** [proj3] Error 1
> x == guess[i];
> ^
> proj3.cc:202:20: error: ISO C++ forbids comparison between pointer and integer [-fpermissive]
> proj3.cc:208:23: warning: pointer to a function used in arithmetic [-Wpointer-arith]
> y == solution[i];
> ^
> proj3.cc:208:23: error: ISO C++ forbids comparison between pointer and integer [-fpermissive]
And what are the declarations for guess and solution?
From the diagnostic, they are names of functions.
Did you intend x == guess(i); and y == solution(i);