I am using 2 ARRAYS OF DIFFERENT SIZES in One 2-Dimensional Vector, and my output is not correct. The arrays are size 4 and size 13.
I want COLUMN 0 to have: 55, 66, 77, 88.
I want COLUMNs 1-12 to have 1,2,3,4,5,6,7,8,9,10,10,10,11 in EACH ROW. It would seem that the 2nd loop for the size 13 array would need to loop 4 times in order to fill 4 rows, however, I'm not sure how to do that. Here is what I have so far in code and output:
------------------------------------Code:#include <iostream> #include <vector> using namespace std; int main() { int typeArray[4] = {55,66,77,88}; int valArray[13] = {1,2,3,4,5,6,7,8,9,10,10,10,11}; // 3 = LENGTH or NUMBER of ROWS; 2 = WIDTH or NUMBER of COLUMNS; // 0 = VALUE all cells are initialized to // using 2 "for loops" vector< vector <int> > myVector(4, vector<int> (13,0)); for (int i = 0; i < myVector.size(); i++) { myVector[i][0] = typeArray[i]; for (int j = 0; j < myVector[i].size(); j++) { myVector[1][j] = valArray[j]; } } // print vector to screen with 4 ROWS, 13 COLUMNS for (int i = 0; i < 4; i++) { for (int j = 0; j < 13; j++) { cout << myVector[i][j] << ' '; } cout << '\n'; } system("Pause"); return 0; }
OUTPUT:
55 0 0 0 0 0 0 0 0 0 0 0 0
1 2 3 4 5 6 7 8 9 10 10 10 11
77 0 0 0 0 0 0 0 0 0 0 0 0
88 0 0 0 0 0 0 0 0 0 0 0 0
-----------------------------
Please advise how to populate rows correctly, thank you.