1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73
|
#include <iostream>
#include <iomanip>
using namespace std;
void getlist(int [], int &); // user inputs list
void printlist(const int [], int); // prints the array
float meanAverage(const int [], int); // finds the average of the array
// finds the differences between the items in the array
void findDifferences(float, const int [], int);
const int ARRAYSIZE = 25; // array size
int j, list[ARRAYSIZE]; // general array
int diff[ARRAYSIZE]; // array for finding differences
int main()
{
int num_items;
float average;
getlist(list, num_items); //user inputs array values
printlist(list, num_items); //prints users array
average = meanAverage(list, num_items); //calculates the average of the users array
cout << "The average of your array is "
<< average << endl << endl;
findDifferences(average, list, num_items);
printlist(diff, num_items);
system("pause");
return 0;
}
void getlist(int list[], int & num_items)
{
cout << "Please enter the number of array values: ";
cin >> num_items;
cout << "Enter the first array value: ";
cin >> list[j];
for(int i = 1; i < num_items; i++)
{
cout << "Enter the next array value: ";
cin >> list[j];
}
}
void printlist(const int list[], int num_items)
{
for(int i = 0; i < num_items; i++)
cout << setiosflags(ios::right) << setw(4)
<< "[" << i << "]"
<< setw(5) << list[j] << endl;
}
float meanAverage(const int list[], int num_items)
{
float total = 0;
for(int i = 0; i < num_items; i++)
total = total + list[j];
return total / num_items;
}
void findDifferences(int average, const int list[], int num_items)
{
for(int i = 0; i < num_items; i++)
diff[j] = list[j] - average;
}
|