#include <iostream>
#include <iomanip>
int main()
{
//Curly braces prevent "Garbage" Integers," These cause no real anwer to ever be stated
int numOfData{};
int sum{};
int average{};
double num[100]{};
int i = 0;
std::cout << std::fixed << std::setprecision(6);
//Prints Message
std::cout << "\n How many numbers would you like ? max 100 : ";
std::cin >> numOfData;
while (numOfData > 100 || numOfData <= 0)
{
std::cout << "\n Error! number should in range of (1 to 100).";
std::cout << "\n Enter the number again:";
std::cin >> numOfData;
}
//Loop executed until 'i' is filled
for (i = 0; i < numOfData; i++)
{
std::cout << ". Enter number " << i + 1 << ": ";
std::cin >> num[i];
sum += num[i];
}
//average = sum / numOfData;
average = static_cast<double>(sum) / static_cast<double>(numOfData);
std::cout << "\n The average is: " << average;
return 0;
}
if this is too much to muddle thru, if I recall you can sort the input and sum in either direction and its 'pretty good'.
you could also just make average a double, so you can get decimal places. you set it to int...
:P (this is the real answer. the above 2 are just some things that you may find interesting, but probably don't want to code up at this point in your studies).