"...Make your subject line reflect your question well enough that the next guy
searching the archive with a question similar to yours will be able to follow the
thread to an answer rather than posting the question again..."
Have input array of size 10, have dupe array of size 5 (because you can't have more than 5 dupes)
int DupeAmt = 0; //records how many dupes are in the dupe array
Request for 10 numbers.
Open input loop, from 0 to 10. Call this InputCnt.
Each number is added to the input array.
Within the input loop, write a second loop that iterates through the existing inputs whose initial index is 0 and max is InputCnt (because we can only iterate through existing inputs) - call this DupeCnt
Check to see if the number you are currently adding ( input[InputCnt] ) is already on the input array.
Catch any dupe numbers. Do not place into Dupe array yet.
Init DupeLoop to 0 (outside of your loop)
Write a third loop to iterate through your dupe array to make sure that dupe doesn't already exist on there. It will start at 0 and end DupeCnt.
Check to see if the dupe number already exists on the dupe array, if it is, break.
End dupe check loop.
If the loop breaks out earlier than its end param of DupeCnt that means there must exist a dupe that already is on the list (because we use the 'break' keyword to break out of the loop if the dupe is found). If DupeLoop equals DupeCnt that means our loop finished without finding this dupe within our list.
if( DupeLoop == DupeCnt )
{
add this dupe to the dupe array
++DupeAmt;
}
Perform outputs of dupes iterating only to DupeAmt.
//---
Used only information that you have provided me - a faster implementation (but slightly more complex would be to use lists and insert sorting O(n))
Hey,
Thanks again all. I got the middle post, I'll be more thoughtful and put a meingful name on it next time. Thanks for continuing me along my start to programming. I'll post again.
enduser000
constint InArSize = 10;
constint DupeArSize = 5;
int InputArray[InArSize];
int DupeArray[DupeArSize];
for( int InputCnt = 0; InputCnt < InArSize; ++InputCnt)
{
//ask for user input here
int DupeCnt;
//we're iterating through the beginning of our InputArray up to the point of
//input count - this is how we check through the length of the array.
for( DupeCnt = 0; DupeCnt < InputCnt; ++DupeCnt )
{
if( InputArray[InputCnt] == InputArray[DupeCnt] )
break;
}
//this will be true if this is a dupe
if( DupeCnt != InputCnt )
{
//insert 3rd array here to check for dupes on the dupe array
}
}