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 <iomanip>
using namespace std;
const int COLS = 4; //Global constants
const int TBL1_ROWS = 3;
const int TBL2_ROWS = 3;
void showArray(const int[][COLS], int); //Function prototype
int main() //Main
{
int table1[TBL1_ROWS][COLS] = {{16, 18, 23, 34},
{54, 91, 11, 48},
{18, 27, 9, 81}};
int table2[TBL2_ROWS][COLS] = {{24, 52, 77, 31},
{16, 19, 59, 67},
{73, 60, 7, 12}};
showArray(table1, TBL1_ROWS); //Displaying arrays
showArray(table2, TBL2_ROWS);
/* HERES MY PROBLEM, clearly wrong. clearly failing to grasp a few concepts here,
I've been reading but this isn't covered in the text specifically.. adding 2 arrays into 1,
displayed as matrices.. I have a hard time understanding initializing an array with no values
predetermined, then the actual math with the locations in each array is a little over my head,
I semi-understand using integers to hold values and incrementing but it's just not clicking...
int myArray[3][4];
for (int i = 0; i < COLS; i++)
{
for (int j = 0; j < 3; j++)
{
myArray[i][j] = table1[i][j] + table2[i][j];
}
}
cout << myArray;*/
system("pause");
return 0;
}
void showArray(const int numbers[][COLS], int rows) //"Displaying arrays" function
{
for (int x = 0; x < rows; x++)
{
for (int y = 0; y < COLS; y++)
{
cout << setw(4) << numbers[x][y] << " ";
}
cout << endl;
}
}
|