Jump to content

Displaying a text grid

- - - - -

This topic has been archived. This means that you cannot reply to this topic.
8 replies to this topic

#1
The Midnighter

The Midnighter

    Newbie

  • Members
  • PipPip
  • 14 posts
How would I go about creating a text grid?
Something like..

#include <iostream>
using namespace std;

int main()
{
	int i = 0;
	int j = 0;
	for (i; i<4;i++)
			cout << "|_|";
	if (i==4) cout << "\n";
	for (j; j<4; j++)
			cout << "|_|";
	if (j==4) cout << "\n";

	system("PAUSE");
	return EXIT_SUCCESS;
}

God I have no idea xD

#2
G_Morgan

G_Morgan

    Programming God

  • Members
  • PipPipPipPipPipPipPip
  • 537 posts
I think you are better off not doing this in ASCII text. At least, if you want to put something in your grid.

#3
mokszyk

mokszyk

    Learning Programmer

  • Members
  • PipPipPip
  • 33 posts
i will help you, tommorow earlier :) just wait [my time: 23:05 now]
THink positive :)

#4
Nix

Nix

    Newbie

  • Members
  • Pip
  • 2 posts
Could you make an example of how an output should look?

#5
mokszyk

mokszyk

    Learning Programmer

  • Members
  • PipPipPip
  • 33 posts
try
[highlight="c++"]For (i = 1 ;i<= Lwierszy; i++)
{
For (j = 1;j<=Lwierszy - i; j++)
{
cout << " ";
}

For (j = 1;j<= i * 2 - 1; j++)
{
cout << "*";
}
For (j = 1; j<= Lwierszy - i; j++)
{
cout << " ";
{

}[/highlight]
THink positive :)

#6
The Midnighter

The Midnighter

    Newbie

  • Members
  • PipPip
  • 14 posts
Why couldn't I use ASCII?
What would you suggest?

I want it to look something like:

Couldn't get underline to work with any sort of formatting, so imagine the boxes are closed in.


_____________________

|  |  |  |  |  |  |  |

|  |  |  |  |  |  |  |

|  |  |  |  |  |  |  |

|  |  |  |  |  |  |  |

|  |  |  |  |  |  |  |


#7
mokszyk

mokszyk

    Learning Programmer

  • Members
  • PipPipPip
  • 33 posts
sorry i made mistake, i can't help you
THink positive :)

#8
G_Morgan

G_Morgan

    Programming God

  • Members
  • PipPipPipPipPipPipPip
  • 537 posts

The Midnighter said:

Why couldn't I use ASCII?
What would you suggest?

I want it to look something like:

Couldn't get underline to work with any sort of formatting, so imagine the boxes are closed in.


_____________________

|  |  |  |  |  |  |  |

|  |  |  |  |  |  |  |

|  |  |  |  |  |  |  |

|  |  |  |  |  |  |  |

|  |  |  |  |  |  |  |

Well the issues I had was how do you do corners and how do you fill in the boxes. If you don't care about the corners then you can do it easily with a 3x3 grid forming a single cell as below

-----
| | |
-----

It looks slightly better in a terminal.

#9
The Midnighter

The Midnighter

    Newbie

  • Members
  • PipPip
  • 14 posts
Progress.

#include <iostream>

#include <stdlib.h>

#include <stdio.h>

#include <time.h>

 

using namespace std;


#define GRST 2

 

char grid[3][3];

void _writeGrid(int flag);


int main()

{

	_writeGrid(GRST);

	system("PAUSE");

	return EXIT_SUCCESS;

}

 

void _writeGrid(int flag) {

    int i, j;

 

    if (flag == GRST) {

        for (i=0;i<3;i++) {

            for (j=0;j<3;j++) {

				cout << "|_|" << grid[i][j];

            }

            cout << endl << endl;

        }

    } 

}

Out puts like:

 

|_| |_| |_|


|_| |_| |_|


|_| |_| |_|