Arrays, how to find if some number is the element of an array.
Well im trying to figure out arrays and such and working on a program to find if a number inputed by the user belongs to a particular array. this is what i have so far and im kinda stuck as i got no idea how to make the next step.
So i have initialized 2 arrays with different numbers and im asking the user to find a number. When the user lets say, enters 4. The program should say 4 is in ArrayA, if the user enters 7 then the program should say 7 is in ArrayB. Any suggestions?
Code:
#include <iostream>
using namespace std;
int main()
{
int ArrElement;
int *pArrElement =&ArrElement;
int ArrayA[8];
int ArrayB[8];
for (int i =0; i<5; i++)
{
ArrayA[i] = i+1;
cout << "ArrayA["<< i << "]: " << ArrayA[i] << "\n";
cout <<"\n";
}
for (int j=5; j<10; j++)
{
ArrayB[j] = j+1;
cout << "ArrayB["<< j << "]: " << ArrayB[j] << "\n";
cout <<"\n";
}
cout << "Find a number between 1 and 10 \n";
cin >> ArrElement;
cout << *pArrElement << " belongs to ArrayA\n";
return 0;
}