Thread: how unlimited the amount of numbers to average

1. how unlimited the amount of numbers to average

Hey Guys!!
I need some help with this.
I want to find a more efficient way to do this. I also want it to have a unlimited amount of numbers that one can average:
Code:
```#include <iostream>
#include <stdlib.h>

using namespace std;
int main(int argc, char * argv[])

{

int selection;

cout<<" Welcome to Average Those Numbers!"<<endl
<<"---------------------------------"<<endl
<<endl
<<"Type in the amount of numbers you would like to average:"<<endl;

cin>>selection;

if (selection == 1)
{
float average;
return 0;
}
if (selection == 2)
{
float average;
return 0;
}
if (selection == 3)
{
float average;
return 0;
}
if (selection == 4)
{
float average;
return 0;
}
if (selection == 5)
{
float average;
return 0;
}
if (selection == 6)
{
float average;
return 0;
}
if (selection == 7)
{
float average;
return 0;
}
if (selection == 8)
{
float average;
return 0;
}
if (selection == 9)
{
float average;
return 0;
}
if (selection == 10)
{
float average;
return 0;
}
else
{
system("PAUSE");
}

return 0;

}```
Thank-you so much!
best regards,
Matthew Johnson

2. Use arrays. Ie
Code:
```float Numbers[20] = {1, 74, ...etc};

int Num = 0;
cout << "Type in the amount of numbers you want to average: ";
cin >> Num;

float Total;

for (int X = 0; X != Num, X++)
{
Total = Total + Numbers[X];
}

// Divide
Total = Total / Num;

cout << "The total is: " << Total;```

3. If you want an unlimited amount, look into the STL containers, most notably vectors:
Code:
```vector<float> grades;
float num=0, total=0, avg=0;

while (1)
{
cout<<"---->";
cin>>num;
if (num==-1)
break;
total+=num;
}

cout<<"The average test score is "<<avg<<endl;```

4. Or you could simply do away with saving the grades to begin with if all you need is the average. Then you would only be constrained by the size limitations of the summation type you use:
Code:
```#include <iostream>

using namespace std;

int main()
{
long  sum = 0;
long  n = 0;

cout<<"Now averaging grades, type Q to quit"<<endl;