-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFunctions-on-array-data.cpp
More file actions
53 lines (39 loc) · 1.18 KB
/
Functions-on-array-data.cpp
File metadata and controls
53 lines (39 loc) · 1.18 KB
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
//CSC 160 Graded lab excercise #2
//Purpose: Write program
//Author: Larsen J Close Most recent changes: 4/15/16
#include <iostream> // preprocessor directive
#include <iomanip> // needed for most manipulators
using namespace std; // using directive
double average(double x[], int y);
double sum( double m[], int p);
int main ( void )
{
const int N = 5;
double weight[N] = {12.3, 31.5, 64.1, 27.8, 45.7}; //weight lbs for N zots
cout << fixed << setprecision(2);
cout << "The average weight of " << N << " zots is ";
cout << average(weight, N) << " lbs\n";
cout << "The total weight of " << N << " zots is ";
cout << sum(weight, N) << " lbs.\n";
system("pause");
return 0;
} //end main()
double average(double x[], int y)
{
double average = sum(x, y)/5;
return average;
}
double sum( double m[], int p)
{
double total = 0;
for (int n = 0; n < p; n++)
{
total = total + m[n];
}
return total;
}
/*
The average weight of 5 zots is 36.28 lbs
The total weight of 5 zots is 181.40 lbs.
Press any key to continue . . .
*/