Multidimensional Array Problem

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • orangemonkey
    New Member
    • Apr 2007
    • 16

    Multidimensional Array Problem

    Hey, my program is doing freaky things.
    I'm trying to store pairs of values, but my program doesn't store them right.

    For instance, if I input 2 for moves, then 1,2,3,4, the program outputs 1,3,3,4.
    I can't put my head around why it won't output 1,2,3,4 and it outputs 1,3,3,4.


    #include <iostream>
    using namespace std;
    int main(void){

    int moves;
    int cmoves [40][1];

    cin >> moves;
    for (int i =0; i<moves; i++)
    {
    cin >> cmoves[i][0];
    cin >> cmoves[i][1];
    }

    for (int i2 =0; i2<moves; i2++)
    {
    cout << cmoves[i2][0];
    cout << cmoves[i2][1];
    }

    cin >> moves;

    }
  • manjuks
    New Member
    • Dec 2007
    • 72

    #2
    Originally posted by orangemonkey
    Hey, my program is doing freaky things.
    I'm trying to store pairs of values, but my program doesn't store them right.

    For instance, if I input 2 for moves, then 1,2,3,4, the program outputs 1,3,3,4.
    I can't put my head around why it won't output 1,2,3,4 and it outputs 1,3,3,4.


    #include <iostream>
    using namespace std;
    int main(void){

    int moves;
    int cmoves [40][1];

    cin >> moves;
    for (int i =0; i<moves; i++)
    {
    cin >> cmoves[i][0];
    cin >> cmoves[i][1];
    }

    for (int i2 =0; i2<moves; i2++)
    {
    cout << cmoves[i2][0];
    cout << cmoves[i2][1];
    }

    cin >> moves;

    }
    Hi,
    The problem is with int cmoves [40][1]; this declaration. make it int cmoves [40][2]; It will work fine.

    Regards,
    Manju

    Comment

    Working...