Welcome to Dream.In.Code
Become a C++ Expert!

Join 149,938 C++ Programmers for FREE! Get instant access to thousands of C++ experts, tutorials, code snippets, and more! There are 1,428 people online right now. Registration is fast and FREE... Join Now!




Array appears as a column, not a board

 
Reply to this topicStart new topic

Array appears as a column, not a board, Battle-Ship like game...tell me if you have heard that one.

Delta_Echo
4 Jan, 2008 - 05:01 AM
Post #1

D.I.C Regular
***

Joined: 24 Oct, 2007
Posts: 480


My Contributions
Ok, im working on a game like battleship, but you have to protect an island.
Anyway before i write the game I made a program to try to better understand arrays, i think i understand most of it.
However, i need it to display like this:

XXX
XXX
XXX

and it displays like this:

X
X
X
X
X
X
X
X
X

This is my code:

CODE


#include <iostream>
#include <stdlib.h>
#include <cstring>
#include <fstream>

using namespace std;

int main()
{
    const int ROWS = 3;
    const int COLUMNS = 3;
    
    char board[ROWS][COLUMNS]=  
    
    // Board
    
    {  
      { 'X', 'X', 'Y', },
      { 'D', 'G', 'G', },
      { 'k', 'X', 'T', },
    };
        
       for ( int i = 0; i < ROWS; i++ )
       {
          
           for ( int j = 0; j < COLUMNS; j++)
           {
               cout << board[i][j];
               cout << endl;
           }
          
       }
       cin.get();
       return 0;
}  
          


Any ideas? Thanks

User is offlineProfile CardPM
+Quote Post

Amadeus
RE: Array Appears As A Column, Not A Board
4 Jan, 2008 - 05:33 AM
Post #2

g++ -o drink whiskey.cpp
Group Icon

Joined: 12 Jul, 2002
Posts: 12,353



Thanked: 51 times
Dream Kudos: 25
My Contributions
You are outputting a newline after every character output - you only want to output the newline every third time, or every row has been completed
CODE

       for ( int i = 0; i < ROWS; i++ )
       {
          
           for ( int j = 0; j < COLUMNS; j++)
           {
               cout << board[i][j];

           }
          cout << endl;  
       }


User is online!Profile CardPM
+Quote Post

Delta_Echo
RE: Array Appears As A Column, Not A Board
4 Jan, 2008 - 05:57 AM
Post #3

D.I.C Regular
***

Joined: 24 Oct, 2007
Posts: 480


My Contributions
THANKS!
User is offlineProfile CardPM
+Quote Post

Reply to this topicStart new topic
Time is now: 1/8/09 04:31PM

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter

Live C++ Help!

C++ Tutorials

Reference Sheets

C++ Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month