so this the output ..
How many numbers? 4
Enter a positive number: 4
Enter a positive number:0
Invalid Input ! Try again!
Enter a positive number: 6
Enter a positive number: 4
Enter a positive number:-1
Invalid Input ! Try again!
Enter a positive number: 7
The Value is 4 6 4 7
Enter a number to be searched: 4
Found at indices: 0 2
This is my codes. But theres an error when it comes to the finding the index of the searched number.. There's always a "Not Found". Whats my error ? Help?!
When the program comes here x will have the same value as size, so num[x] will try to access the element that is after the last element in the array. You probably want to use a loop to compare a with the elements in the array.
...
cout<<endl;
cout<<"Enter a number to be searched: ";
cin>>a;
for (x=0; x<size; x++) {
if (num[x] == a)
cout << x << " ";
elseif (x == size-1)
cout << "Not Found!";
}
getch();
...