search element by index arrays help please

This is a code to find element by index of an array inputted. However it does not work can you please help me what I have to change?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
 #include<iostream>
using namespace std;

int main()
{
    const int SIZE = 5;
    int a[5] , TheNum, i;
    for( int i=0;i<5;i++){cin>>a[i]; }
    cout << "Number to search for: ";
    cin >> TheNum;
    
    for(i = 0; i < SIZE; i++)
    {
        if(i == TheNum){
            cout << "You found " << TheNum << " at MrArray[" << a[i] << "].";
            i = SIZE+1;
            break;
        }
    }
    
    }
#include<iostream>
using namespace std;

int main()
{
const int SIZE = 5;
int a[5] , TheNum, i;
for( int i=0;i<5;i++){cin>>a[i]; }
cout << "indexi: ";
cin >> TheNum;

for(i = 0; i < SIZE; i++)
{
if(i == TheNum){
cout << "Tkven ipovet " << TheNum << " es elementi[" << a[i] << "].";

break;
}
}

}

I did it, if anyone will need it.
I think you've gotten something switched in your head. >_>

What goes between the brackets is the index of the element of the array you want to access (0 - 4 in this case). a[i] is the element of the array at index i.

I'm assuming your code was supposed to look through the 5-element array and get the index of an element whose value matches TheNum. If so, then lines 14 and 15 need changing. You just need to switch two things in those lines (but not the whole lines).

-Albatross
Topic archived. No new replies allowed.