Hi all,
I am currently in the 17th tutorial in the C++ series (Variable argument list in C++)
and i can successfully make programs with functions with unknown length of argument list....
in that Alex Allain says that another way of doing it rather than using
cstdarg is to make a function that accepts a pointer to an array...
i've made a program and wanna know if that is what he meant...
Code:
#include<iostream>
using namespace std;
void avg(int size,int *a){
int sum = 0,avg = 0,x;
for(x = 0; x < size; x++){
sum += *(a + x);
}
avg = sum / size;
cout << "The average of the numbers is " << avg << "...";
}
int main(){
cout << "How many numbers's average would you like to find? ";
int size;
cin >> size;
cin.ignore();
int array[size];
for(int a = 0; a < size; a++){
cout << "Enter number " << a + 1 << " here: ";
cin >> array[a];
cin.ignore();
}
int *a = array;
avg(size,a);
cin.get();
}