Click to See Complete Forum and Search --> : How do I search an array?


Redhill
April 16th, 2005, 08:18 PM
For my programme, I have a list of 10 numbers. I'm supposed to ask the user to enter an index number between 0 and 9, validate it, then write out the value of the array with that index.

If there's one thing I really don't get in C++ programming, it's Arrays. Any help would be awesome!

Sahir
April 16th, 2005, 11:38 PM
Post the code you have written so far.

g_gili
April 19th, 2005, 05:44 AM
I don't undestand your request verry well but I understood that you want to learn abot arrays you get an array like int a[100] that contains 101 integers everry array has an index like a[0],a[1],a[2]...a[100];
to set values to the arrays
int n,a[100];
cin>>n;
for(int i=0;i<=n;i++)
cin>>a[i];
///
your request is that you ask a number!

int a[100],b;
cout<<"Enter an index between 0-9:";
cin>>b;
if(b>=0&&b<=9)
cout<<a[b];
else
cin>>b