Jul 6, 2014 at 4:56pm UTC
error says "cannot convert 'int*' to 'int' in function main()
and also
type mismatch in parameter in function sort(int,int)
heres the code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40
#include<iostream.h>
#include<conio.h>
void main()
{
void sort(int ,int );
clrscr();
int Arr[20],i,n;
cout<<"Enter the size of the array:" ;
cin>>n;
cout<<"Enter the elements of the array:" ;
for (i=0;i<n;i++)
cin>>Arr[i];
cout<<"The unsorted array is...\n" ;
for (i=0;i<n;i++)
cout<<Arr[i]<<" " ;
sort(Arr,n);
getch();
}
void sort(int A[],int num)
{
int i,j,small,pos;
for (i=0;i<num;i++)
{
small=A[i];
pos=i;
for (j=i+1;j<num;j++)
if (A[j]<small)
{
small=A[i];
pos=j;
}
}
int temp=A[i];
A[i]=A[pos];
A[pos]=temp;
cout<<"The sorted array...\n" ;
for (i=0;i<num;i++)
cout<<A[i]<<" " ;
}
Last edited on Jul 6, 2014 at 5:16pm UTC
Jul 6, 2014 at 5:13pm UTC
Your function prototype and function definition don't match. The prototype tells the compiler that the function will take two integers, but you send in and the function is defined to take an integer array and an integer.
void sort(int ,int );
void sort(int A[],int num)
Jul 6, 2014 at 5:24pm UTC
The A isn't necessary, but the [] is, it tells the compiler to expect an array.
Jul 6, 2014 at 5:27pm UTC
Shouldn't matter whether you have a space there or not.
Jul 6, 2014 at 5:28pm UTC
man output is wrong. when i enter 1,2,4,5,3
unsorted is 1 2 4 5 3
but sorted is 1 2 4 5 9215
help
Jul 6, 2014 at 5:39pm UTC
If your sort logic isn't working, might be good to step through the sort function to see how the values are changing (or not).
Jul 6, 2014 at 5:49pm UTC
Also - the function prototype (line 5) should get pulled out of the main function and be put before main begins.
Jul 6, 2014 at 5:55pm UTC
oh man, no idea where i went wrong. can u pls find it out? i gotta submit this program tomorrow.