473,323 Members | 1,574 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,323 software developers and data experts.

2d arrays

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

Expand|Select|Wrap|Line Numbers
  1. include <iostream>
  2. using namespace std;
  3.  
  4. const int PIXEL_1 = 177;
  5. const int PIXEL_2 = 176;
  6.  
  7. const int MAXROWS = 3 , MAXCOLUMNS = 3;
  8.  
  9. void initalise (int pixel_array[][MAXCOLUMNS], int size_of_first_dimension);
  10. void print_array ();
  11.  
  12.  
  13. int main ()
  14. {    
  15.     int num_array [MAXROWS][MAXCOLUMNS];
  16.     cout << " Please enter the DN values for num_array [0],[0]." << endl;
  17.     int dn_value;
  18.     cin >> dn_value;
  19.  
  20.  
  21.  
  22.     initalise (num_array, MAXROWS);
  23.  
  24.     for (int row = 0; row < MAXROWS; row++)
  25.     {
  26.         for (int column = 0; column < MAXCOLUMNS; column++)
  27.             {
  28.                 cout << num_array[row][column] << char ( PIXEL_1 );
  29.             }
  30.         cout << endl;
  31.     }
  32.  
  33.     return 0;
  34. }
  35.  
  36.  
  37. void initalise (int this_array[][MAXCOLUMNS], int size_of_first_dimension) 
  38. {
  39.     int i = char ( PIXEL_1 ), j = char ( PIXEL_2 );
  40.  
  41.     for (i = 0; i < size_of_first_dimension; i++)
  42.         for (j = 0; j < MAXCOLUMNS; j++)
  43.         {
  44.             this_array[i][j] = char ( PIXEL_2 );
  45.         }
Nov 19 '07 #1
4 1245
sicarie
4,677 Expert Mod 4TB
Nice code. Does it run? Where are you stuck? What are you trying to do? Does that code work? Are there compile errors? Logical errors?

Please read the rules of posting to this site before blindly posting again.
Nov 19 '07 #2
hi yes it does run but what i want to do is fill each individual array with a different colouered block from the ascii code which is specified as a constant in my code. the dn values will just be a number that corrosponds to the coloured block which will be displayed. I hope this helps. Thanks
Nov 19 '07 #3
sicarie
4,677 Expert Mod 4TB
And have you tried this? Is it not working? Where are you stuck?

Did you read the link I posted when I asked you to read that before blindly posting again?
Nov 19 '07 #4
And have you tried this? Is it not working? Where are you stuck?

Did you read the link I posted when I asked you to read that before blindly posting again?

Hi yes it works but it prints out 00 along witht the character blocks. I anm just wondering how to assign the users input to the array.
Thanks
Nov 19 '07 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

19
by: Canonical Latin | last post by:
"Leor Zolman" <leor@bdsoft.com> wrote > "Canonical Latin" <javaplus@hotmail.com> wrote: > > > ... > >But I'm still curious as to the rational of having type >...
21
by: Matteo Settenvini | last post by:
Ok, I'm quite a newbie, so this question may appear silly. I'm using g++ 3.3.x. I had been taught that an array isn't a lot different from a pointer (in fact you can use the pointer arithmetics to...
5
by: JezB | last post by:
What's the easiest way to concatenate arrays ? For example, I want a list of files that match one of 3 search patterns, so I need something like DirectoryInfo ld = new DirectoryInfo(searchDir);...
3
by: Michel Rouzic | last post by:
It's the first time I try using structs, and I'm getting confused with it and can't make it work properly I firstly define the structure by this : typedef struct { char *l1; int *l2; int Nval; }...
1
by: Rob Griffiths | last post by:
Can anyone explain to me the difference between an element type and a component type? In the java literature, arrays are said to have component types, whereas collections from the Collections...
41
by: Rene Nyffenegger | last post by:
Hello everyone. I am not fluent in JavaScript, so I might overlook the obvious. But in all other programming languages that I know and that have associative arrays, or hashes, the elements in...
6
by: Robert Bravery | last post by:
Hi all, Can some one show me how to achieve a cross product of arrays. So that if I had two arrays (could be any number) with three elements in each (once again could be any number) I would get:...
1
by: Doug_J_W | last post by:
I have a Visual Basic (2005) project that contains around twenty embedded text files as resources. The text files contain two columns of real numbers that are separated by tab deliminator, and are...
16
by: mike3 | last post by:
(I'm xposting this to both comp.lang.c++ and comp.os.ms- windows.programmer.win32 since there's Windows material in here as well as questions related to standard C++. Not sure how that'd go over...
29
weaknessforcats
by: weaknessforcats | last post by:
Arrays Revealed Introduction Arrays are the built-in containers of C and C++. This article assumes the reader has some experiece with arrays and array syntax but is not clear on a )exactly how...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.