this error"too many arguments to function"

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • xtoma
    New Member
    • Feb 2015
    • 11

    this error"too many arguments to function"

    I am trying to compile bubble sort program and i get a error message back. "In function ... too many arguments to function. What does this mean?
    can you give me the soultion

    ...
    #include<iostre am>
    using namespace std;
    void swap ( int A[]);

    int main()
    {
    int n,i,j;
    int A[4];
    int temp;
    cout<<"please,e nter size of element in array";
    cin>>n;
    cout<<"please,e nter numbers of elements in array";
    cin>>A[i];

    for(i=n-1;i>=1;i--)
    {
    for(j=0;j<=i-1;j++)
    {
    if(A[j]>A[j+1])
    swap(A,j);
    {

    temp=A[j];
    A[j]=A[j+1];
    A[j+1]=temp;
    }
    }
    }
    cout<<"element befor sorte are:";
    {
    else
    cout<<"element after sort are:";

    system("pause") ;
    }
    Attached Files
  • weaknessforcats
    Recognized Expert Expert
    • Mar 2007
    • 9214

    #2
    Your function prototype says swap has one argument:

    Code:
    void swap ( int A[]);
    But when you call it, you use two arguments:

    Code:
    swap(A,j);

    Comment

    • xtoma
      New Member
      • Feb 2015
      • 11

      #3
      expected primary-expression before &quot;else&quot ;

      Code:
      if(A[j]>A[j+1])
                   swap(A);
                   {  
                             temp=A[j];
                             A[j]=A[j+1];
                             A[j+1]=temp;
                             }
                             }
                             }
                             cout<<"element befor sorte are:"<<endl;
      [B]else[/B]
                             cout<<"element after sort are:"<<endl;
                             system("pause");
                             }
      but
      here another problem expected primary-expression before "else"
      Last edited by Stewart Ross; Feb 21 '15, 09:41 AM. Reason: added code tags for you

      Comment

      • donbock
        Recognized Expert Top Contributor
        • Mar 2008
        • 2427

        #4
        It is hard to tell because the braces in your excerpt don't match up.

        Proper if-then-else format is
        Code:
        if (condition)
            statement;
        else
            statement;
        Either of those statements can be a compound statement:
        Code:
        {
        statement;
        ...
        statement;
        }
        It looks like you have more than one statement between the if and the else.

        Comment

        Working...