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 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92
|
[code]#include <iostream>
using namespace std;
[code]int main() {
//hardcode the input values... initialisation of 2d array
char sentinel = 'X', oper;
cout << " Jan " << "\t" << " Feb " " Mar " " Apr " " May " " Jun \n";
int table[3][6] = { { 800000, 700000, 750000, 800000, 650000, 700000 },
{ 250000, 300000, 350000, 400000, 400000, 420000 },
{ 150000, 200000, 180000, 120000, 150000, 200000 } };
//print the value
for (int rows = 0; rows < 3; rows++) {
for (int cols = 0; cols < 6; cols++) {
cout << table[rows][cols] << " ";
}
cout << endl;
}
//print average of each row
int sum[3] = { 0,0,0 };
for (int rows = 0; rows < 3; rows++) {
for (int cols = 0; cols < 6; cols++) {
sum[rows] = sum[rows] + table[rows][cols];
}
}
int min, max;
min = sum[0];
max = sum[0];
int most_sale = 0;
int least_sale = 0;
for (int rows = 0; rows < 3; rows++) {
if (min >= sum[rows]) {
least_sale = rows + 1;
min = sum[rows];
}
if (max <= sum[rows]) {
most_sale = rows + 1;
max = sum[rows];
}
}
for (int rows = 0; rows < 3; rows++) {
cout << "Sum of each store " << rows + 1 << " is " << sum[rows] << endl;
cout << "Average sale of each store " << rows << " is " << float(sum[rows]) / 6.0 << endl << endl;
}
cout << "Lowest sale is store " << least_sale << endl;
cout << "Highest sale is store " << most_sale << endl;
system("pause");
do {
int StartM = 0;
int EndM = 0;
int table[3][6] = { { 800000, 700000, 750000, 800000, 650000, 700000 },
{ 250000, 300000, 350000, 400000, 400000, 420000 },
{ 150000, 200000, 180000, 120000, 150000, 200000 } };
cout << "Enter start of the month for calculation" << endl;
cin >> StartM;
cout << "Enter end of the month for calucation" << endl;
cin >> EndM;
if ((StartM > 0) && StartM <= 6) && (EndM > 0 && EndM <= 6) && (EndM >= StartM))
{
// Store 1 value
for (int StartM = 0; StartM < EndM; StartM++)
{
sum[StartM] = sum[StartM] + table[0][StartM];
}
// Store 2 value
for (int StartM = 0; StartM < EndM; StartM++)
{
sum[StartM] = sum[StartM] + table[1][StartM];
}
//Store 3 value
for (int StartM = 0; StartM < EndM; StartM++)
{
sum[StartM] = 0; StartM + table[2][StartM];
}
for (int cols = 0; cols < 6; cols++) {
cout << "The total sale is: " << sum[cols] << endl;
cout << "Press E to exit or any other key to continue" << endl;
}
};
else (
cout << "Please enter Start & End month" << endl;
);
} while (toupper(sentinel) != 'E');
}
|