By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,973 Members | 1,854 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,973 IT Pros & Developers. It's quick & easy.

error: call of a non function

P: 17
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<iostream.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,min_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,num3,num4);

min(num1,num2,num3,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<iostream.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
Nov 19 '06 #1
Share this Question
Share on Google+
1 Reply


Expert 100+
P: 1,510
in main() you define two local variables max and min which 'hide" the functions max() and min(), when you attempt to call the functions
Expand|Select|Wrap|Line Numbers
  1. max(num1,num2,num3,num4);
  2. min(num1,num2,num3,num4);
  3.  
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.
Nov 19 '06 #2

Post your reply

Sign in to post your reply or Sign up for a free account.