Code:
#include <cstdarg>
#include <iostream>
using namespace std;
double average ( int num, ... )
{
va_list arguments;
double sum = 0;
va_start ( arguments, num );
for ( int x = 0; x < num; x++ )
sum += va_arg ( arguments, double );
va_end ( arguments );
return sum / num;
}
int main()
{
cout<< average ( 3, 12.2, 22.3, 4.5 ) <<endl;
cout<< average ( 5, 3.3, 2.2, 1.1, 5.5, 3.3 ) <<endl;
cin.get();
}
It's not the best code in the world but im still learning. Anyways, a while back i made a code that multiplied two seperate integers that were input (aren't i amazing), this is relavent i guess because whenever i try to run this code, it keeps popping up my multiplication code. I mean WTF!!!!:confused: