This program works if I skip the first 3 arguments in the list but if I send "average(3, 0,1,2)" it works without skiping the first three arguments, as it should. Why can I not send the array?
Thanks for any help you can give me.
double average(int num,...)
{
va_list arguments;
double extra;
double numbers[25];
va_start(arguments,num);
double sum=0;
for(int x=0;x<num+3;x++)
{
if(x>2) //why do I have to do this to make this program work?
{
sum+=va_arg(arguments,double);
cout<<"\nso far "<<sum;
}
else
{
extra=va_arg(arguments,double);
}
}
va_end(arguments);
return sum/(double)num;
}
int main()
{
int q=25;
double mynum[25];
for(int x=0;x<=3;x++)
{
mynum[x]=(double)x;
}
cout<<endl<<"The Average is "<<average(x,mynum);
return 0;
}