Can't figure out the issue!

#include <iostream>
using namespace std;
int main()
{
// 1. Declare and use an array of 10 integers in your main function.
const int n = 10;
int array[n];

// 2. Collect 10 integer values from the user and store these in the array
for (int i = 0; i<n; i++)
{
cout << "Enter value " << (i + 1) << " : ";
cin >> array[i];
}


// 3. Create and call a function that takes the array as an argument and returns the smallest value in the array.
int smallest(int array[], int n)
{
int small = array[0];
for (int i = 1; i < n; i++)
if (array[i] < small) small = array[i];
return small;
}

// 4. Create and call a function that takes the array as an argument and returns the largest value in the array.
int largest(int array[], int n)
{
int large = array[0];
for (int i = 1; i<n; i++)
if (array[i]>large) large = array[i];
return large;
}
// 5. Create and call a function that takes the array as an argument and returns the sum of the array values.

int sum(int array[], int n)
{
int sum = 0;
for (int i = 0; i < n; i++) sum += array[i];
return sum;
}

// 6. Create and call a function that takes the array as an argument and returns the average of the array values.

double average(int array[], int n)
{
return static_cast<double> (sum(array, n)) / n;
}

// 7. Create and call a function that takes the array as an argument and reverses the order of the values in the array.
void reverse(int array[], int n)
{
for (int i = 0; i < n / 2; i++)
{
int temp = array[i];
array[i] = array[n - i - 1];
array[n - i - 1] = temp;
}
}

// 8. Create and call a function takes the array as an argument and that will print out the values in the array.
void print(int array[], int n)
{
cout << array[0];
for (int i = 1; i < n; i++)
{
cout << ", " << array[i];
}
}


// 9. Display the smallest value in the array for the user.
cout << "Smallest value in array is " << smallest(array, n) << endl;

// 10. Display the largest value in the array for the user.
cout << "Largest value in array is " << largest(array, n) << endl;

// 11. Display the sum of the values in the array for the user.
cout << "Sum of values in array is " << sum(array, n) << endl;

// 12. Display the average of the values in the array for the user
cout << "Average of values in array is " << average(array, n) << endl;

// 13. Display the values in the array before it is reversed and after it is reversed
print(array, n);
reverse(array, n);
cout << endl << "After reversing array " << endl;
print(array, n);
cin.sync(); cin.get();
return 0;
}
Last edited on
I've tried making the int function a stand alone and various other things but the code just wont work!
I think i figured it out.. I put the main function at the end and included it with the rest instead of trying to encompass the whole thing.
Topic archived. No new replies allowed.