error: call of a non function

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • greek
    New Member
    • Nov 2006
    • 17

    error: call of a non function

    Hi!
    I'm suppode to write a prg to calculate maximum and minimum of 4 intergers by using functions
    i've writen the code but getting the error: call of a non function..cant see my error help me..here is my code

    #include<iostre am.h>
    #include<conio. h>
    void max(int a,int b,int c,int d);
    void min(int a,int b,int c,int d);
    int num1,num2,num3, num4,max_val,mi n_val;
    void main()
    {clrscr();
    int num1,num2,num3, num4,max,min;
    cout<<"Input 4 integer values"<<endl;
    cin>>num1>>num2 >>num3>>num4;

    max(num1,num2,n um3,num4);

    min(num1,num2,n um3,num4);

    getch();
    }

    void max(int a,int b,int c,int d)
    { max_val=a;
    if (b>max_val)
    max_val=b;
    if (c>max_val)
    max_val=c;
    if (d>max_val)
    max_val=d;
    cout<<"The maximum integer value is:"<<max_val<< endl;
    }

    void min(int a,int b,int c,int d)
    { min_val=a;
    if (b<min_val)
    min_val=b;
    if (c<min_val)
    min_val=c;
    if (d<min_val)
    min_val=d;
    cout<<"The minimum integer value is:"<<min_val<< endl;
    }

    Same error when am dong another program for calculating the average of 4 integers..
    here is my code

    #include<iostre am.h>
    #include<conio. h>
    float avg(int a,int b,int c,int d);
    void main()
    {clrscr();
    int w,x,y,z;
    float avg;
    cout<<"Input four numbers"<<endl;
    cin>>w>>x>>y>>z ;
    cout<<"The average of the four numbers is:"<<avg(w,x,y ,z)<<endl;
    }
    float avg(int a,int b,int c,int d)
    {float p;
    p=(a+b+c+d)/4;
    return p;
    }

    plz help me find my error
    thx alot
  • horace1
    Recognized Expert Top Contributor
    • Nov 2006
    • 1510

    #2
    in main() you define two local variables max and min which 'hide" the functions max() and min(), when you attempt to call the functions
    Code:
    max(num1,num2,num3,num4);
    min(num1,num2,num3,num4);
    the compiler thinks you are calling the local variables as though they are functions

    remove the max and min local variables and the program works.

    Comment

    Working...