-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPointerToArrayAddress.cpp
More file actions
50 lines (39 loc) · 1.06 KB
/
PointerToArrayAddress.cpp
File metadata and controls
50 lines (39 loc) · 1.06 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
/************************************************
This program uses two different notations
when dealing with a pointer variable that
is accepting an array address as an argument
************************************************/
#include <iostream>
#include <iomanip>
using namespace std;
void getSales(double *, int);
double totalSales(double *, int);
int main(){
const int QTRS = 4;
double sales[QTRS];
//Get the sales data
getSales(sales, QTRS);
//Set the numeric output formatting
cout << fixed << showpoint << setprecision(2);
//Display the total sales for the year
cout << "The total sales for the year are $";
cout << totalSales(sales, QTRS) << endl;
return 0;
}
void getSales(double *arr, int size){
for(int count=0; count<size; count++){
cout << "Enter the sales figure for quarter ";
cout << (count + 1) << ": ";
cin >> arr[count];
}
}
double totalSales(double *arr, int size){
double sum = 0.0;
for(int count=0; count<size; count++){
sum += *arr;
arr++;
cout << "\nThis could be the array address: " << arr;
cout << endl;
}
return sum;
}