Then wantedval = -1 and you know you didn't find it.
Note make the initial value of wantedval outside the range of numbers you are expecting in the array.
You must also have a flag that indicates the value is actually found in the array.
A common way is to initialize the position with -1, as this is (In C++) not a valid array index.
int wantedpos = -1;
... search...
if (wantedPos != -1) // it really is found in the array.
Another problem can be that value occur more than once in an array.
In that case you need to define if you want to find the 1st 2nd .... last instance.
Thankyou WizenedEE , I have used your script above and run very well...I just modified symbol of "=" be "=="
I've spent a lot of time to find this script that I use to get index numbering..
const int arysz = 6;
int ary[arysz] = {4, 32, 6, 2, -1, 5}
int wantedval = -1;
int wantedpos;
for (int i=0; i<arysz; i++) {
if (wantedval == ary*) { //modified here*
Not exactly. The post was made without code tags and turned into italics at that point. The array index was interpreted as a command to use italics, instead of being displayed. This is one of the reasons why code tags MUST be used!