Printing an Array to the screen

This is a discussion on Printing an Array to the screen within the C++ Programming forums, part of the General Programming Boards category; I have an array that is char floor[20][20]. I am using x and y as the variables in the array ...

  1. #1
    Registered User
    Join Date
    Oct 2001
    Posts
    30

    Printing an Array to the screen

    I have an array that is char floor[20][20]. I am using x and y as the variables in the array and I want to print the array to the screen. I read over the section on here about arrays and I just dont know how to print the aray to the screen. right now I have it set up as a cout statement:
    std::cout<<floor[x][y]

    This is not working. Do I have it set up wrong or is there an error in my program? Thanks for any help.

  2. #2
    Registered User
    Join Date
    Oct 2001
    Posts
    30
    Ok here is my full code.
    Attached Files Attached Files

  3. #3
    Registered User
    Join Date
    Sep 2001
    Posts
    85
    if you want to output the whole array, you need a loop. what you did will only cout one element. try this:

    for(int i=0; i<20;i++){
    for(int j=0; j<20;j++)
    cout<<floor[i][j]<<" ";
    cout<<endl;
    }

  4. #4
    Unregistered
    Guest
    Thank you very much, That worked. But I encurred another problem. For some reason it is always readin the penstatus as being down. Any idea on what could cause this?

  5. #5
    Registered User
    Join Date
    Sep 2001
    Posts
    85
    it could be because you did not initialize up and down to any numbers. try setting down to 0, and up to 1.

    or you could try this:

    enum PENSTATUS{up,down};
    PENSTATUS pen =down;

    enum makes penstatus a new data type, which can be set equal to up or down.

  6. #6
    Registered User
    Join Date
    Oct 2001
    Posts
    30
    O.k. Thank you for the help. That was the problem. After soving that problem though another one arose. That is the fact that I belive my turtle is starting out in the top left corner. It is supposed to start out in the bottom left corner. Anybody have any idea on how to fix that?

  7. #7
    Unregistered
    Guest
    const int Max = 10;
    const int Max = 10;

    int array[MAX][MAX];

    array[0][0] is upper left corner
    array[9][0] is lower left corner
    array[0][9] is upper right corner
    array[9][9] is lower right corner

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. printing in screen
    By imagetvr in forum C++ Programming
    Replies: 2
    Last Post: 08-16-2008, 10:35 AM
  2. Merge sort please
    By vasanth in forum C Programming
    Replies: 2
    Last Post: 11-09-2003, 11:09 AM
  3. Struct *** initialization
    By Saravanan in forum C Programming
    Replies: 20
    Last Post: 10-09-2003, 12:04 PM
  4. Array Program
    By emmx in forum C Programming
    Replies: 3
    Last Post: 08-31-2003, 12:44 AM
  5. Help with an Array
    By omalleys in forum C Programming
    Replies: 1
    Last Post: 07-01-2002, 08:31 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21