Hello swingby,
This will give you an idea of your program:
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 <sstream>
using namespace std; // <--- Best not to use.
int main()
{
constexpr int MAXRWOS{ 10 };
constexpr int MAXCOLS{ 10 };
std::istringstream mxSS{ "-1 -1 -4 -4 -1 -1 -1 -5 -5 -1 -1 -1 -1 -9 -1 -1 -6 -7 -8 -1" };
std::istringstream subMxSS{ "1 1 4 5 3 4 3 4 2 2 3 4" };
int row{4}, col{5}, totalIntensity{3}, matrix[MAXRWOS][MAXCOLS]{}, subMatrix[MAXRWOS][MAXCOLS]{};
// <--- Needs a prompt.
//std::cin >> row >> col;
for (int mxRow = 1; mxRow <= row; mxRow++)
{
for (int mxCol = 1; mxCol <= col; mxCol++)
{
// <--- Needs a prompt.
//std::cin >> matrix[mxRow][mxCol];
mxSS >> matrix[mxRow][mxCol];
}
}
// <--- Needs a prompt.
//std::cin >> totalIntensity;
for (int subRow = 0; subRow < row - 1; subRow++)
{
for (int subCol = 0; subCol < col - 1; subCol++)
{
// <--- Needs a prompt.
//std::cin >> subMatrix[subRow][subCol];
subMxSS >> subMatrix[subRow][subCol];
}
}
return 0; // <--- Not required, but makes a good break point.
}
|
Lines 2, 11 and 12 are just for testing. You do not need them. This just means that you do not have to type something with the "cin" statements every time the program runs leaving more time to focus on the rest of the code.
All of your for loops start at (1). C++ like other languages are (0)zero based, so your arrays will start at (0) not (1). Starting at (1) you are skipping element (0) of the array. Sometimes this can be useful, but most of the time it is not.
Also it is a good policy to initialize your variables when defined.
Notice the changes in the second for loop. This will work better for you, but you still can make better use of the for loop. My idea is to get it working properly with what you are more likely to understand first.
I moved lines 30 and 31 to after the 2nd for loop because it has nothing to do with the 2nd for loop.
This should get you started. after that you need to follow the directions and finish your code.
Andy