Arrray confusion

You are given  an int variable  k , an int array  zipcodeList that has been declared  and initialized , an int variable  nZips that contains the number of elements  in zipcodeList , and a bool  variable  duplicates .


Write some code that assigns  true  to duplicates if there are two adjacent elements  in the array  that have the same value , and that assigns  false  to duplicates otherwise.

Use only k , zipcodeList , nZips , and duplicates .


Here is my solution.

1
2
3
4
5
6
7
duplicates = false;

for(k = 0; k < nZips && !duplicates; k++)
if(zipcodeList[k] == !duplicates)
  {
  duplicates = true;
   }


Here is what they keep telling me I'm doing wrong, which I don't understand.

Your code does not assign true to duplicates when there are two adjacent elements with the same value in the array.
duplicates is a boolean. Why are you comparing an int to a bool? O.O

You have the general structure of the solution done, it's just that the bounds of your for loop need to be smaller (which side is smaller doesn't matter) and what you're comparing zipcodeList[k] to needs to be different.

-Albatross
Topic archived. No new replies allowed.