Small Error Where Is It?

This is just a sample program I did to display the Exsel Sort except I'm getting a couple errors which I know are simple:

Errors:

1.)3 C:\Users\-6\Desktop\Dev-Cpp\ESC\Exsel Sort.cpp expected constructor, destructor, or type conversion before ';' token
2.) C:\Users\-6\Desktop\Dev-Cpp\ESC\Exsel Sort.cpp In function `int main()':
3.)17 C:\Users\-6\Desktop\Dev-Cpp\ESC\Exsel Sort.cpp no matching function for call to `swap(int[10], int&, int)'
4.)23 C:\Users\-6\Desktop\Dev-Cpp\ESC\Exsel Sort.cpp no matching function for call to `swap(int[10], int&, int&)'
5.)23 C:\Users\-6\Desktop\Dev-Cpp\ESC\Exsel Sort.cpp At global scope:
6.)31 C:\Users\-6\Desktop\Dev-Cpp\ESC\Exsel Sort.cpp ISO C++ forbids declaration of `swap' with no type

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
#include<iostream>
using namespace std;
swap(int[],int,int);
main(){
       int slot[10]={8,3,1,5,7,10,4,9,6,2};
       int n=10,i;
       int lower,upper,sortflag,sml,scan;
       lower=0;
       upper=n-1;
       sortflag=1;
       while((lower<upper)&&(sortflag==1)){
              sml=lower;
              sortflag=0;
              scan=lower+1;
              while(scan<=upper-lower){
              if(slot[scan]>slot[scan+1]){
                       swap(slot,scan,scan+1);
                       sortflag=1;
                       if(slot[scan]<slot[sml]) sml=scan;
                       }//IF
              scan++;
              }//WHILE
       swap(slot,lower,sml);
       upper=upper-1;
       lower=lower+1;
       }//WHILE
       cout<<"AFTER SORT:"<<endl;
       for(i=0;i<n;i++) cout<<slot[i]<<" ";
       cout<<endl;
       return 0;     }//MAIN
swap(int slot[],int i,int j){
         int temp;
         temp=slot[i];
         slot[i]=slot[j];
         slot[j]=temp;
         return 0;     }//SWAP 


What am I doing wrong?
It compiled successfully for me.

Proof: http://i.imgur.com/KLLl6.png

1
2
3
int main(void) {
      return 0;
}

You should always specify a return type for main.
Last edited on
I don't know why mine won't I even did this:

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
#include<iostream>
using namespace std;
swap (int[],int,int);
int main(void){
       int slot[10]={8,3,1,5,7,10,4,9,6,2};
       int n=10,i;
       int lower,upper,sortflag,sml,scan;
       lower=0;
       upper=n-1;
       sortflag=1;
       while((lower<upper)&&(sortflag==1)){
              sml=lower;
              sortflag=0;
              scan=lower+1;
              while(scan<=upper-lower){
              if(slot[scan]>slot[scan+1]){
                       swap(slot,scan,scan+1);
                       sortflag=1;
                       if(slot[scan]<slot[sml]) sml=scan;
                       }//IF
              scan++;
              }//WHILE
       swap(slot,lower,sml);
       upper=upper-1;
       lower=lower+1;
       }//WHILE
       cout<<"AFTER SORT:"<<endl;
       for(i=0;i<n;i++)cout<<slot[i]<<" ";
       cout<<endl;
       system("PAUSE");
       return 0;     }//MAIN
swap(int slot[],int i,int j){
         int temp;
         temp=slot[i];
         slot[i]=slot[j];
         slot[j]=temp;
         return 0;     }//SWAP 


The heck am I doing wrong? Can you paste your code?
Last edited on
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
#include <iostream>
using namespace std;
swap (int[],int,int);
int main(void){
       int slot[10]={8,3,1,5,7,10,4,9,6,2};
       int n=10,i;
       int lower,upper,sortflag,sml,scan;
       lower=0;
       upper=n-1;
       sortflag=1;
       while((lower<upper)&&(sortflag==1)){
              sml=lower;
              sortflag=0;
              scan=lower+1;
              while(scan<=upper-lower){
              if(slot[scan]>slot[scan+1]){
                       swap(slot,scan,scan+1);
                       sortflag=1;
                       if(slot[scan]<slot[sml]) sml=scan;
                       }//IF
              scan++;
              }//WHILE
       swap(slot,lower,sml);
       upper=upper-1;
       lower=lower+1;
       }//WHILE
       cout<<"AFTER SORT:"<<endl;
       for(i=0;i<n;i++)cout<<slot[i]<<" ";
       cout<<endl;
       return 0;     }//MAIN
swap(int slot[],int i,int j){
         int temp;
         temp=slot[i];
         slot[i]=slot[j];
         slot[j]=temp;
         return 0;     }//SWAP  


What compiler are you using?
Dev c++
That's an IDE, not a compiler.
Yeah for some reason I'm getting a problem with this:
swap (int[],int,int);

Dev C++ usually compiles and executes though idk what the problem is
I suspect you need to use a pointer...

You're passing an array by value, rather than by reference...

this is where the importance of what compiler you are using comes in, some compilers will pick up this has occurred, and fix it for you.
Last edited on
closed account (DSLq5Di1)
6.)31 C:\Users\-6\Desktop\Dev-Cpp\ESC\Exsel Sort.cpp ISO C++ forbids declaration of `swap' with no type

swap(int slot[],int i,int j){ // return type is missing

Don't forget to update the declaration on line 3 too.
Topic archived. No new replies allowed.