Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New to the CF scene
    Join Date
    Sep 2011
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Strange Runtime Error

    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?

    Code:
    #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;
    }
    Last edited by Phratello; 09-27-2011 at 06:40 PM.

  • #2
    Rockstar Coder
    Join Date
    Jun 2002
    Location
    USA
    Posts
    9,074
    Thanks
    1
    Thanked 328 Times in 324 Posts
    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.
    OracleGuy


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •