Thread: Rofl where did I go wrong ? Need Help Plz !

  1. #1
    Registered User
    Join Date
    Feb 2002
    Posts
    52

    Rofl where did I go wrong ? Need Help Plz !

    I just want it to print the cells of the array, yet when it is supposed to print 10 for each cell I get 4 happy faces, then another row starts and 2 happy faces print.... All I can say is WTF I checked then code, many times; still can't figure whats up. THe thing that makes me mad is I know its a simple mistake.

    #include<stdio.h>
    #include<conio.h>
    #include<math.h>

    void main(void)
    {
    int i,j;
    double x,y;
    double A[2][3];
    for(i=0;i<3;i++)
    {
    for(j=0;j<4;j++)
    {
    A[i][j] = 10;
    printf(A[i][j]"\t");
    }
    printf("\n")
    }
    getch();
    }
    Last edited by Halo; 04-15-2002 at 09:49 PM.

  2. #2
    Registered User
    Join Date
    Mar 2002
    Posts
    95
    up readup on the usage of printf: it should be
    Code:
    printf("%f\n",A[i][j]);
    cant remember if its %f or somethin else but just have a quick read and you'll be able to find it all, I know float is %f
    printf(A[i][j]"\t");
    actually thats not the only problem, you are accessing **** too high proram should be somethin like:
    Code:
    void main(void) 
    { 
      int i,j; 
      double x,y; 
      double A[2][3]; 
      for(i=0;i<2;i++) 
      { 
        for(j=0;j<3;j++) 
        { 
          A[i][j] = 10; 
          printf(A[i][j]"\t"); 
        } 
        printf("\n") 
      } 
      getch(); 
    }
    because doing:
    double A[2][3]; means using index's:
    A[0][0];
    A[0][1];
    A[0][2];
    A[1][0];
    A[1][1];
    A[1][2];

  3. #3
    Registered User
    Join Date
    Feb 2002
    Posts
    52
    double A[2][3]; means using index's:
    A[0][0];
    A[0][1];
    A[0][2];
    A[1][0];
    A[1][1];
    A[1][2];

    I though this would have an array of 3x4 what your saying is my array is now 2x3 ?

  4. #4
    Registered User foniks munkee's Avatar
    Join Date
    Nov 2001
    Posts
    343
    When you declare an array like such..
    Code:
    double A[2][3];
    you are declaring an array that has 2 X 3 elements, however when you index those elements it will be indexed as such:
    Code:
    A[0][0]
    A[0][1]
    A[0][2]
    A[1][0]
    A[1][1]
    A[1][2]

  5. #5
    Registered User
    Join Date
    Mar 2002
    Posts
    95
    the numbers you specify when declaring the array is the exact number you can use so as you have
    double A[2][3];
    it means you have 2 rows, and 3 colums or 6 cells, now when you want to access a cell you get it and minus 1, so if you want to manipulate the first cell you would have:
    Code:
    A[0][0] = whatever;
    may take a little to get used to it but you'll pick it up pretty easy, become second nature soon.

  6. #6
    Me want cookie! Monster's Avatar
    Join Date
    Dec 2001
    Posts
    680
    Originally posted by Halo
    double A[2][3]; means using index's:
    A[0][0];
    A[0][1];
    A[0][2];
    A[1][0];
    A[1][1];
    A[1][2];

    I though this would have an array of 3x4 what your saying is my array is now 2x3 ?

    Huh? Are you a Visual Basic programmer or something like that?

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. can any1 plz make this assignment
    By jean in forum C Programming
    Replies: 17
    Last Post: 05-13-2009, 09:19 PM
  2. [Request] Need Help Plz
    By TylerD in forum Tech Board
    Replies: 4
    Last Post: 01-03-2009, 09:54 AM
  3. Confused: What is wrong with void??
    By Machewy in forum C++ Programming
    Replies: 19
    Last Post: 04-15-2003, 12:40 PM
  4. God
    By datainjector in forum A Brief History of Cprogramming.com
    Replies: 746
    Last Post: 12-22-2002, 12:01 PM
  5. Whats wrong?
    By Unregistered in forum C Programming
    Replies: 6
    Last Post: 07-14-2002, 01:04 PM