...

View Full Version : Strange Runtime Error



Phratello
09-27-2011, 06:34 PM
I don't know everything seems to be in order here but I'm getting a runtime bug where the code continues in an infinite loop printing numbers until it crashes. Perhaps someone can enlightening me as to what the problem is?



#include <iostream>

using namespace std;

int main()
{
int matrixA[2][3] =
{
{-5, 2, 8},
{1, 0, 0}
};

int matrixB[2][3] =
{
{1, 0, 2},
{0, 3, -6}
};

int matrixC[2][3] =
{
{0, 0, 0},
{0, 0, 0}
};

for(int i = 0; i < 2; i++)
{
for(int k = 0; i < 3; k++)
cout << matrixA[i][k] << " ";
cout << endl;
}
return 0;
}

oracleguy
09-27-2011, 07:38 PM
Look at your inner for loop: for(int k = 0; i < 3; k++) It is running while i is less than 3, when it should be checking against k. Hence your infinite loop.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum