#include <iostream>
usingnamespace std;
int sortArray(int userArray, int arraySize);
int main()
{
int arraySize = 0;
cout << "\nThis program creates an array of various numbers and will sort them." << endl;
cout << "\nHow large would you like the array? ";
cin >> arraySize;
int* userArray[] = { newint[arraySize] };
//make user input values
for (int i = 0; i < arraySize; i++)
{
cout << "Please input integer #" << i << ": " << endl;
cin >> userArray[i];
}
for (int i = 0; i < arraySize; i++)
{
cout << "userArray{" << i << "] = " << userArray[i];
}
delete[]userArray;
cout << "The average is: " << sortArray[](userArray, arraySize) << endl;
}
int sortArray(int* userArray, int arraySize)
{
int i;
float avg, sum = 0;
for(i = 0; i < arraySize; i++)
{
sum += userArray[i];
}
avg = sum/arraySize;
return avg;
}
#include <iostream>
usingnamespace std;
double avgArray(constint* userArray, size_t arraySize);
int main()
{
size_t arraySize {};
cout << "\nThis program creates an array of various numbers and will sort them.\n";
cout << "\nHow large would you like the array? ";
cin >> arraySize;
constauto userArray {newint[arraySize] {}};
//make user input values
for (size_t i = 0; i < arraySize; ++i) {
cout << "Please input integer #" << i << ": ";
cin >> userArray[i];
}
for (size_t i = 0; i < arraySize; ++i)
cout << "\nuserArray{" << i << "] = " << userArray[i];
cout << "\n\nThe average is: " << avgArray(userArray, arraySize) << '\n';
delete[] userArray;
}
double avgArray(constint* userArray, size_t arraySize)
{
double sum {};
for (size_t i = 0; i < arraySize; ++i)
sum += userArray[i];
return sum / arraySize;
}