2d arrays

2d arrays

Page 1 of 1

2 Replies - 933 Views - Last Post: 19 November 2007 - 06:16 AM Rate Topic: -----

#1 sugarflaps  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 13
  • Joined: 11-October 07

2d arrays

Post icon  Posted 19 November 2007 - 03:38 AM

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 );
		}
}


Is This A Good Question/Topic? 0
  • +

Replies To: 2d arrays

#2 no2pencil  Icon User is offline

  • Toubabo Koomi
  • member icon

Reputation: 5182
  • View blog
  • Posts: 26,886
  • Joined: 10-May 07

Re: 2d arrays

Posted 19 November 2007 - 06:11 AM

View Postsugarflaps, on 19 Nov, 2007 - 04:38 AM, said:

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.


Ok, I don't understand the project I guess. What is a 'dn' value?

Also, are you getting an error with your code?
Was This Post Helpful? 0
  • +
  • -

#3 sugarflaps  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 13
  • Joined: 11-October 07

Re: 2d arrays

Posted 19 November 2007 - 06:16 AM

View Postno2pencil, on 19 Nov, 2007 - 06:11 AM, said:

View Postsugarflaps, on 19 Nov, 2007 - 04:38 AM, said:

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.


Ok, I don't understand the project I guess. What is a 'dn' value?

Also, are you getting an error with your code?



Hi,
A dn value is just a number to corrospond with the characters im using. Im tring to fill the two dimensional array with the characters specified so it kind of prints out an image of gray and black blocks. I know i have the loops right as they print out but i cant get the individual arrays filled with the characters.
Thanks i hope this helps
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1