1. ## Beginner help

I am on the section in the tutorials about an indeterminate amount of function arguments. I have tried to change the example to allow user input and have ran into a problem with it. It is just a simple average calculator that is supposed to get user input for numbers to find the average of. It is probably an easy fix but i'm still learning and can't figure out what is wrong with the code. If i leave it as is there are no errors from the compiler. If I enter one number it returns the value "inf" if more than one the program crashes. Any help would be greatly appreciated.

Code:
```#include <cstdarg>
#include <iostream>

using namespace std;

char numbers[150];

double average ( int num, ... )
{
va_list numbers[2];
double sum = 0;

va_start (numbers[2], num);
for (int x=0;x<num;x++)
sum += va_arg (numbers[2], double);
va_end (numbers[2]);

return sum / num;
}
int main()
{
cout<<"Please enter numbers to find the average): "<<endl;
cin.getline ( numbers, 150);
cout<<average (numbers[2])<<endl;
}```

2. O_O

Can you give me a link to the tutorial you are using?

Soma

3. You are only passing one argument to average. In my opinion, variable argument lists are not appropriate here: you effectively changed the problem into one for which the solution is no longer applicable.

4. variable argument lists are not appropriate here
I'm not entirely sure that they are ever appropriate.

Soma

5. It is the tutorial on cprogramming.com. It was the first tutorial I found so I decided to go through it. Cprogramming.com Tutorial: Variable Argument Lists for Functions that is where i'm at on it. I am just using what the tutorial was using.
If I understand correctly the string only counts as one argument. If so that would mean that I didn't even accomplish what I was going for. Well thank you for the help anyway. I will just move on with the tutorial then.

6. numbers is a char array, and the first argument to average is an int. How can you NOT get a compile error? Something is not right.
Also, you should use std::getline instead of std::cin.getline.

7. Originally Posted by phantomotap
I'm not entirely sure that they are ever appropriate.

Soma
In C++ maybe not, but in C have a look at printf.

8. But C is an ancient language stuck in 1950, and this is the C++ forum, so C is not applicable here.