My head hurts trying to debug my crappy C++ code..help!

Discussion in 'OT Technology' started by totaly, Oct 4, 2003.

  1. totaly

    totaly Guest

    this is what its suppose to print:
    1
    2 2
    3 3 3
    4 4 4 4
    5 5 5 5 5
    6 6 6 6 6 6
    7 7 7 7 7 7 7
    8 8 8 8 8 8 8 8
    9 9 9 9 9 9 9 9 9
    10 10 10 10 10 10 10 10 10 10

    But instead, it keeps printing:
    1
    12
    123
    1234
    12345
    1233456
    12345678

    heres what i tryed to do:
    #include <iostream>

    using std::cout;
    using std::endl;

    int main()
    {
    int iRow;
    int iColumn;


    iRow = 1;

    while (iRow < 10)
    {
    for (iColumn = 1; iColumn < iRow; iColumn++)
    {
    cout << iColumn << " ";
    }
    cout << endl;

    iRow++;
    }

    return 0;
    }


    can anyone help?
     
  2. Astro

    Astro Code Monkey

    Joined:
    Mar 18, 2000
    Messages:
    2,047
    Likes Received:
    0
    Location:
    Cleveland Ohio
    I think you're on the right track, you just need to swap variables:

    Code:
    cout << iColumn << " ";
    
    Instead I think should be:
    Code:
    cout << iRow << " ";
    
     
  3. oasis

    oasis Guest

    you should be printing out iRow instead of iColumn, iColumn should start at 0, and the outer while loop should be while (iRow < 11).
     
  4. CyberBullets

    CyberBullets I reach to the sky, and call out your name. If I c

    Joined:
    Nov 13, 2001
    Messages:
    11,865
    Likes Received:
    0
    Location:
    BC, Canada/Stockholm, Sweden
    ^^^^^^^^ what they said

    is this ur 1st c++ program?
     

Share This Page