I have an int myArray[4], and I want to insert a little code to check and make sure that all four items in the array are different integers.
I want to avoid this big long if statement, if I can:
[code=c++]
if(myArray[0] != myArray[1] && myArray[0] != myArray[2] && myArray[0] != myArray[3] && myArray[1] != myArray[2] && myArray[1] != myArray[3] && myArray[2] != myArray[3])
{
cout << myArray;
}
else
{
}
[/code]
It's ok for int myArray[4], but if I have int myArray[8] it becomes really cumbersome.
Any ideas?
Thank you!
You will need a loop. Do it for three, four and five by hand first, the algorithm should be clear by then.