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
|
#include <iostream>
#include <string>
#include <cmath>
#include <iomanip>
using namespace std;
int main() {
cout << "Retail \nStore" << "\t" << " Jan " << "\t" << " Feb " << "\t" << " Mar " << "\t" << " Apr " << "\t" << "May " << "\t" << " Jun \n";
// 2D array Initialisation [3 rows and 7 columns]
int table[3][7] = { { 1, 800000, 700000, 750000, 800000, 650000, 700000 },{ 2, 250000, 300000, 350000, 400000, 400000, 420000 },{ 3, 150000, 200000, 180000, 120000, 150000, 200000 } };
//2D array display
for (int rows = 0; rows<3; rows++) {
for (int cols = 0; cols<7; cols++)
cout << table[rows][cols] << "\t"; //change to cin if you want to read data to 2D array
cout << endl;
}
cin.ignore();
}
float compute(int a, int b, int c)
{
int ave1 = 0;
int total1 = 0;
int ave2 = 0;
int total2 = 0;
int ave3 = 0;
int total3 = 0;
int x;
int store1[6] = { 800000, 700000, 750000, 800000, 650000, 700000 };
int store2[6] = { 250000, 300000, 350000, 400000, 400000, 420000 };
int store3[6] = { 150000, 200000, 180000, 120000, 150000, 200000 };
for (x = 0; x < a; x++)
{
total1 = total1 + store1[x];
ave1 = total1 / a;
}
for (x = 0; x < b; x++)
{
total2 = total2 + store2[x];
ave2 = total2 / b;
}
for (x = 0; x < c; x++)
{
total3 = total3 + store3[x];
ave3 = total3 / c;
}
cout << "Average is %d for store 1\nAverage is %d for store 2\nAverage is %d for store 3\n", ave1, ave2, ave3;
cin.ignore();
return 0;
}
|