Hi im trying to print out rows and columns using ascai characters to resemble pixels. I am trying to get the user to input the dn values for the array and then use these values to then print out the appropriate character. Im really stuck now and have been at this for days any help would be great as i have to hand this in today. Heres my code below thankyou

#include <iostream>
using namespace std;

const int PIXEL_1 = 177;
const int PIXEL_2 = 176;

const int MAXROWS = 3 , MAXCOLUMNS = 3;

void initalise (int pixel_array[][MAXCOLUMNS], int size_of_first_dimension);
void print_array ();


int main ()
{    
    int num_array [MAXROWS][MAXCOLUMNS];
    cout << " Please enter the DN values for num_array [0],[0]." << endl;
    int dn_value;
    cin >> dn_value;

    

    initalise (num_array, MAXROWS);

    for (int row = 0; row < MAXROWS; row++)
    {
        for (int column = 0; column < MAXCOLUMNS; column++)
            {
                cout << num_array[row][column] << char ( PIXEL_1 );
            }
        cout << endl;
    }

    return 0;
}


void initalise (int this_array[][MAXCOLUMNS], int size_of_first_dimension) 
{
    int i = char ( PIXEL_1 ), j = char ( PIXEL_2 );

    for (i = 0; i < size_of_first_dimension; i++)
        for (j = 0; j < MAXCOLUMNS; j++)
        {
            this_array[i][j] = char ( PIXEL_2 );
        }
}
int i = char ( PIXEL_1 ), j = char ( PIXEL_2 );

This is a very weird line of code.
If you're trying to create an array of chars dynamicly you should look at new and delete
Then in the next line you say: for (i = 0; i < size_of_first_dimension; i++) Which puts 'i' back to 0...

What should the function initalise() do exactly?

Does this even compile?

This is a very weird line of code.
If you're trying to create an array of chars dynamicly you should look at new and delete
Then in the next line you say: for (i = 0; i < size_of_first_dimension; i++) Which puts 'i' back to 0...

What should the function initalise() do exactly?

Does this even compile?

Hi
It does compile but it doesnt do what i want it to do i want to create a 2d array using the black and grey blocks from the ascii code with each dn value being either grey or black.

Perhaps I'm missing the point completly, but why not initialize your array like this:

char Screen[PIXEL_1][PIXEL_2];
for (int i = 0; i < PIXEL_1; i++)
{
    for (int k = 0; k < PIXEL_2; k++)
    {
         Screen[i][k] = (char)178;
    }
}

I didn't compile it, so it might not work...
To view the content of you array you might want to try something like this:

for (int i = 0; i < PIXEL_1; i++)
{
   for (int k = 0; k < PIXEL_2; k++)
   {
      cout << Screen[i][k];
   }
   cout << endl;
}
cin.get();

Again: I didn't try it, it's more of a suggestion

Now all you have to do is ask the user for input and check with an IF-statement if the current value in the loop is the dn'st value (input from user)

Hi
It does compile but it doesnt do what i want it to do i want to create a 2d array using the black and grey blocks from the ascii code with each dn value being either grey or black.

Most of us aren't psychic here. You need to tell us:
1) what the program did
2) what you expected
3) where in the program we should look
Don't leave it up to us to read you code and figure out what's wrong. We need details.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.