-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMultidimensional Arrays.cpp
More file actions
45 lines (33 loc) · 899 Bytes
/
Multidimensional Arrays.cpp
File metadata and controls
45 lines (33 loc) · 899 Bytes
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
#include <iostream>
#include <iomanip>
using namespace std;
//
const int DISTRICS = 4;
const int MONTHS = 3;
int main()
{
setlocale(LC_ALL, "italian");
int d, m;
double sales[DISTRICS][MONTHS]; // 4 righe e 3 colonne: 4 array 1D di lunghezza 3
for (d = 0; d < DISTRICS; d++)
for (m = 0; m < MONTHS; m++)
{
cout << "Enter sales for district " << d +1;
cout << ", month " << m +1 << ": ";
cin >> sales[d][m];
}
cout << "\n\n";
cout << " Month\n";
cout << " 1 2 3";
for (d = 0; d < DISTRICS; d++)
{
cout << "\nDistrict " << d +1;
for (m = 0; m < MONTHS; m++)
cout << setiosflags(ios::fixed) // not exponential
<< setiosflags(ios::showpoint) // always use point
<< setprecision(2) // digits to right 2
<< setw(10) // field width
<< sales[d][m];
}
return 0;
}