Average function using Variadic Functions method

pascal111 judas.the.messiah.111 at gmail.com
Tue Nov 2 16:23:22 UTC 2021


I'm programming average calculating function by using Variadic 
Functions method, but I didn't get yet what is the wrong in my 
code:

// D programming language

import std.stdio;
import core.vararg;
import std.conv;

float foo(...)
{

float x=0;

for(int i=0; i<_arguments.length; ++i){

x+=to!float(_arguments[i]);

}

x/=_arguments.length;

return x;

}

int main()
{


writeln(foo(2,3));

return 0;

}


More information about the Digitalmars-d-learn mailing list