Monday, May 24, 2010

Anybody good w/ C++ arrays? I can't a little bit of code to work.?

You are given two int variables j and 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 any two elements in the array have the same value, and that assigns false to duplicates otherwise.





Use only j , k , zipcodeList , nZips , and duplicates .


__________________________________


Ok so that is the question and here is the code I typed... It doesn't work














for(j=0;j%26lt;nZips;j++)


{


for(k=1;k%26lt;nZips;k++)


{


if(zipcodeList[j]==zipcodeList[k])


duplicates=true;


}


}


if(duplicates!=true)


duplicates=false;

Anybody good w/ C++ arrays? I can't a little bit of code to work.?
// Assume that there are no duplicates


duplicates=false;





for(j=0;j%26lt;(nZips - 1) %26amp;%26amp; !duplicates;j++)


{


for(k=j + 1;k%26lt;nZips %26amp;%26amp; !duplicates;k++)


{


if(zipcodeList[j]==zipcodeList[k])


{


duplicates=true;


}


}


}





Edited the array initializers
Reply:do we have to do your frigging homework for you?


No comments:

Post a Comment