I am trying to write a function with a variable number of parameters without using additional libraries. A function of this type: sum (int number of elements, element1, element2, etc.) For an hour, I have been trying to force my function to count float numbers, but in vain. What am I doing wrong?
#include <iostream> #include <conio.h> float sum (int n, float,...) { int *p = &n; float s = 1; for (int i = 1; i <= n; i++) s*= *(++p); return s; } void main() { std::cout << sum(3,2.2,2.1,2.5); getch(); } At the output I get float numbers in huge degrees.
sum? .. - Harry