c++ - Receiving a runtime error, see photo, during run. Want to expand a spiral matrix -
i @ lost , posting code can situation resolved. relatively new programming , teaching myself c++ dr. bronson's textbook.
here error get:
here code. when put "cout" statement @ head of int main(), still same error.
// 28.pe.numberspiralmatrix.cpp : defines entry point console application. // #include "stdafx.h" #include <iostream> #include <iomanip> using namespace std; const int row = 1001; const int col = 1001; int right(int spiral[row][col], int, int, int, int); int down(int spiral[row][col], int, int, int); int left(int spiral[row][col], int, int, int, int); int up(int spiral[row][col], int, int, int); int main() { cout << "we here!" << endl; int spiral[row][col]; int crow = 4; int ccol = 4; int i, j; int growth = 1, count = 0, count1 = 0, count2 = 0, count3 = 0, count4 = 0, count5 = 0; int inc; (inc = 0; inc < 501; inc++)//increased 1 { growth = right(spiral, growth, count, count1, inc); count++; if (count <= 3 + inc)//increasing count 1 , count1 increased column number. common sense hard see. { count1++; } //cout << growth << endl; if (growth == 1002002) { break; } growth = down(spiral, growth, count2, inc); if (count2 < 3 + inc)// increased 1 5 7; { count2++; } //cout << growth << endl; growth = left(spiral, growth, count3, count4, inc); //cout << growth << endl; if (count3 <= 3 + inc)//increased 1 5 7. { count3++; } if (count4 <= 4 + inc)//increased 1 5 7. { count4++; } growth = up(spiral, growth, count5, inc); //cout << growth << endl; if (count5 < 4+inc)//increased 1 5 7; { count5++; } } return 0; } int right(int spiral[row][col], int growth, int count, int count1, int inc) { int i, j; int count1 = 0; int step; cout << "welcome, here in right." << endl; (j = (4+inc) - count; j <= ((5+inc) + count1); j++) // count: 0 --> 2. increased 1, 5 7. { step = (4+inc) - count; // increased 1, 5 7 spiral[step][j] = growth; growth++; cout << spiral[step][j] << " " << "i: " << step << ", j: " << j << endl; } cout << "growth is: " << growth << endl; return growth; } int down(int spiral[row][col], int growth, int count2, int inc) { int i; int step; int count2 = 0; cout << "welcome, here in down." << endl; (i = (5+inc) - count2; <= (5+inc) + count2; i++)// increased 1 5 7. { step = (5 + inc) + count2; // increased 1 5 7. spiral[i][step] = growth; growth++; cout << spiral[i][step] << ", " << "i: " << << ", " << "j: " << step << endl; } return growth; } int left(int spiral[row][col], int growth, int count3, int count4, int inc) { int j; int step; cout << "welcome, here in left." << endl; (j = (4+inc) + count3; j >= (3+inc) - count3; j--) // count3 , count4 { step = (5+inc) + count3; spiral[step][j] = growth; growth++; cout << spiral[step][j] << ", " << "i: " << step << ", " << "j: " << j << endl; } return growth; } int up(int spiral[row][col], int growth, int count5, int inc) { int i; int step; cout << "welcome, here in up." << endl; (i = (4+inc) + count5; >= (4+inc) - count5; i--)//increased 1 5 7; { step = (3+inc) - count5; //increased 1 5 7. spiral[i][step] = growth; growth++; cout << spiral[i][step] << ", " << "i: " << << ", " << "j: " << step << endl; } return growth; }
Comments
Post a Comment