This is a program my friend passed to me to check. I've found that there are a few errors such as array/pointer types but can't correct them. Can anyone help out? Here's the code, pls debug and tell me the errors. Thanx.
#include<iostream.h>
int search_ordered_array(const int [],int,int);
void sort_array(int [],int);
void input_array(int,int);
int main()
{
const int arraysize=50;
int a[arraysize]={0};
int searchkey,element;
sort_array(a,arraysize);
cout<<"Enter integer search key:\n";
cin>>searchkey;
element=search_ordered_array(a,searchkey,arraysize);
if(element!=-1)
cout<<"Found value in element -->"<<element<<endl;
else
cout<<"Value not found"<<endl;
return 0;
}
void input_array(int list, int score)//SOMETHING WRONG!!!
{
list=50;
int n;
cout<<"\nPlease enter array size:\n";
cin>>n;
cout<<"Please enter values to the test score sheets:\n";
cout<<"And enter (-1) to finish entering values:\n";
for(int i=0;i<n;i++)
{
cin>>score[i];
if (score[i]==-1)
break;
}
}
void sort_array(int a[],int arraysize)
{
int hold,i;
for(int pass=0;pass<arraysize-1;pass++)
for(i=0;i<arraysize-1;i++)
if(a[i]>a[i+1])
{
hold = a[i];
a[i] = a[i+1];
a[i+1] = hold;
}
cout<<"\nData in ascending order:\n";
for(i=0;i<arraysize;i++)
cout<<a[i]<<endl;
}
int search_ordered_array(const int array[],int key,int sizeofarray)
{
for(int n=0;n<sizeofarray;n++)
if(array[n]==key)
return n;
return -1;
}
This code should fix the problem
#include<iostream.h>
int search_ordered_array(const
void sort_array(int [],int);
void input_array(int,int);
int main()
{
const int arraysize=50;
int a[arraysize]={0};
int searchkey,element;
sort_array(a,arraysize);
cout<<"Enter integer search key:\n";
cin>>searchkey;
element=search_ordered_arr
if(element!=-1)
cout<<"Found value in element -->"<<element<<endl;
else
cout<<"Value not found"<<endl;
return 0;
}
void input_array(int list, int score[]) //score[] is an array...
{
list=50;
int n;
cout<<"\nPlease enter array size:\n";
cin>>n;
cout<<"Please enter values to the test score sheets:\n";
cout<<"And enter (-1) to finish entering values:\n";
for(int i=0;i<n;i++)
{
cin>>score[i];
if (score[i]==-1)
break;
}
}
void sort_array(int a[],int arraysize)
{
int hold,i;
for(int pass=0;pass<arraysize-1;pa
for(i=0;i<arraysize-1;i++)
if(a[i]>a[i+1])
{
hold = a[i];
a[i] = a[i+1];
a[i+1] = hold;
}
cout<<"\nData in ascending order:\n";
for(i=0;i<arraysize;i++)
cout<<a[i]<<endl;
}
int search_ordered_array(const
{
for(int n=0;n<sizeofarray;n++)
if(array[n]==key)
return n;
return -1;
}