Can't debug!!

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;
}
LVL 1
Neo78Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

cgallagherCommented:
Your problem is that you tried to use score as an array without actually defining it as an array,
This code should fix the problem


#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[]) //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;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;
}
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
NorbertCommented:
If it is homework please be honest!
void input_array(int list, int score)//SOMETHING WRONG!!!
yes it is
try
void input_array(int list, int* score)

BTW:
input_array is never called
0
cgallagherCommented:
That was a bit stupid writing out all the code again when it was easier to write out the single line...
But on the homework line, Telling him the difference between the parameter being an array and a normal integer is not breaking the rules I would say?
0
Cloud Class® Course: CompTIA Healthcare IT Tech

This course will help prep you to earn the CompTIA Healthcare IT Technician certification showing that you have the knowledge and skills needed to succeed in installing, managing, and troubleshooting IT systems in medical and clinical settings.

NorbertCommented:
But someone who is able to check a program should know the difference between an array and a normal integer:)

Anyway - I know it sometimes happens that I can't see the forest because of the trees :)
0
NorbertCommented:
Helping him at this point will not break the rules - I think.
He did already know where the error was and as nietod says we may help him like a teacher would do.
I am sure a teacher would tell him that he should check the data types.
0
cgallagherCommented:
A teacher would point out an error like that, but I will try to be a little more careful in the future and maybe try and tease the solution out of the person rather than actually giving them the answer. My apologise for stepping in a little quick.
Regards,
C.
0
NorbertCommented:
>>cgallagher did you see that your answer and my first comment occures nearly the same time ?
If I decided to say something there was no other comment or answer
I did never want to flame you !!
we both want to help and we both said nearly the same.
0
Neo78Author Commented:
Thanx to both of you but who should I give the points to? cgallagher I suppose right?
Anyway, this is not my homework and I certainly know the error is the type for score but like Norbert said, you can't see the forest because of the trees....so believe me when I say it's my friend's....
0
NorbertCommented:
I think cgallagher should get the points.
He was the first.
The work looks like a homework so if it is not your own is it the homework of your friend ?
In that case we have the same problem because at last it is homework.
0
cgallagherCommented:
Thats very decent of you Norbert.
Neo, I'm not bothered who you give the points to. I won't be dissapointed no matter who you give them to. Maybe I should get them because I answered first, but if you look at the answering times you'll see that he was probably typing his answer while I was posting mine, so its a close call.
Who's answer did you use?
Are there any rules here that you can check? If so that will be your answer if you are still unsure.

Regards,
C.
0
Neo78Author Commented:
ok guys..thanx to u two
It was my last effort to help my friend...haha
But still when i ran the answer, there was a couple errors tho no one realised them even my friend......Oh well, thanx again and cya....
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
C++

From novice to tech pro — start learning today.