Visite Webhosting Latino, el site sobre alojamiento web.
Help with arrays pleas. - Mombu the Programming Forum
Mombu the Programming Forum sponsored links

Go Back   Mombu the Programming Forum > Programming > Help with arrays pleas.
User Name
REGISTER NOW! Mark Forums Read

sponsored links

1 2nd May 04:44
External User
Posts: 1
Default Help with arrays pleas.

Hi there am using arrays for the first time am learning Turbow pacal 7
at college you see. I have to develpoe a program that outputs codes of
cards and the prices of them. but it has to store the cards and the
costs in array as well as calulating the cost to get the change back
for the customer. So whats the easyest way for me to do this and any
basic advice on understanding arrays will be most appreciated. i
alredy have my psudelcode know thats spelt wrong i have dyslexia you
see. so i have a good idea of the procedures involved. I just a bit
confused with the array bit helpppppp pleassssss thanks all in
  Reply With Quote

  sponsored links

2 2nd May 04:44
markus humm
External User
Posts: 1
Default Help with arrays pleas.

Gaz schrieb:


Why don't you try to write a the program first and show us the code then?
So we'll know better where your problems are and second thing: we don't
do your whole homework for you, because you wouldn't learn that much
from it but rather help where you're stuck. But we don't belive you
stuck already before the first line of source code! Don't do that to us ;-)

Okay, one usefull thing would be, to look up the key word "record" in
the help system, so you could store the code and the price of each card

Greetings and good luck at your first OWN try at this problem

  Reply With Quote
3 2nd May 04:44
External User
Posts: 1
Default Help with arrays pleas.

I have to do the step wise refine ment first which i have almost to
give me ideas of the procedures in the program. Am now tweking it a
bit now before i start to develope the program.I was just was wanting
some tips or guide lines on using array. I was not expecting you to do
it for me i just wanted some pointers in array and how they work.
Am confadint i will get it up and runing ok. Am probly scared of
arrays as i think they seem so complacated and we are only doing
somthing realy simpel with it.Thanks
  Reply With Quote
4 2nd May 04:44
markus humm
External User
Posts: 1
Default Help with arrays pleas.


Okay, that seems quite fair.

I'll shortly explain array to you.
What you surely know are normal variables like Byte, Word, String etc.
they do have one disatvantage: you can only store one item of the
specified sort (e.g. one number or one characterstring) under the same
name. For handling data with the same structure over and over like in
loops, it's not good suited, e.g. for spreadsheet like applications.

Arrays are a larger number of identical typed variables (e.g. several
byte or string vars) packed together under the same name and adressible
by some index.

Now a short example:

program arraytest;

USES crt;

VAR numbers:array[1..5] OF BYTES;
{this are the like vars numbers[1], numbers[2] ... numbers[5]}
summ :WORD;

for loopc:=1 to 5 do

for loopc:=1 to 5 do
writeln('Number ',loopc,' is ',numbers[loopc]);
summ:=summ DIV 5;
writeln('Average is: ',summ);

The program above fills an array of 5 bytes with random numbers and
calculates the average of these 5 numbers afterwards.

The other hint I gave you yesterday was to also use records. With
records, you can store several items of different variable types
together in the same array and adress them with the same index.

Greetings & I hope this helps

  Reply With Quote
5 2nd May 04:44
wolf behrenhoff
External User
Posts: 1
Default Help with arrays pleas.

This should have been ... of Byte; (without s) It is always Array[a..b]
of TYPE.
Before declaring a variable this way, you should think of the type
concept Pascal provides. It is often better to do it this way:
TNumberArray = Array[1..5] of Byte;
var numbers: TNumberArray;

If you want to iterate over the whole array, you should use the High and
Low functions. High returns the highest indes, low the lowest:
for loopc:=Low(numbers) to High(numbers) do ...
This is especially useful if you want to change the array bounds later.

  Reply With Quote
6 2nd May 04:44
clif penn
External User
Posts: 1
Default Help with arrays pleas.

Arrays are used in every computer language and may seem complicated
at first, BUT, they are very useful and become easier with use. As a
simple example, suppose you wish to investigate the statistics of the
dice game, craps. There are scores 2..12 for the 2 dice added
You could declare an array of:
sum:array[2..12] of integer;
Set all sums (sum[2]..sum[12]]) to zero with a "For" loop.
Now you can generate two random numbers, 1..6, and add them together.
If the sum is 6, sum[6] := sum[6] + 1 (or Inc(sum[6]) to keep up with
the number of times a sum of 6 is rolled. After about 1,000 sums are
generated, you will find sum[7] is much larger than either sum[2]
or sum[12].

I am guessing that your comfusion comes when each array element has
more than one thing that varies. A familiar example to you would be an
array of student's names and their test scores. Although it is
POSSIBLE to do this with 2 arrays such as names[] and scores[], this
is hard to keep error free when doing such things as sorting. It is
much easier to declare your own variable type such as:

name:string[20]; {up to 20 chars per name}
end; {type}

class:array[1..15] of student;

When students register, you might have:
class[1].name := Smith, John;
class[7].name := Adams, Helen;
and so on, none of which yet have a score.

You could sort class[] alphabetically for the class roll.
In that case, class[1].name becomes Adams, Helen.

Now when you enter the scores, the score of Helen Adams might be:
class[1].score := 85;

After exams you may wish to print out the names and scores in rank
order of the scores.

The array type variable simplifies these operations.
  Reply With Quote
7 22nd May 02:18
External User
Posts: 1
Default Help with arrays pleas.

Im Artikel <>, (Gaz) schreibt:

Arrays are not so complicated. Think of an array as a street, with houses.
Every array has a fixed (or in Delphi variable) length, and contains members
(houses) of a certain common data type (array[from, to] of ...). The data type
may be "record", it is not restricted to a single basic type (integer,
string...). There may exist undefined elements (houses not yet constructed) in
an array, usually arrays are filled in sequential order and the amount of
entered elements is recorded in an associated variable. Every array element has
an unique array index (house number), by which it can be referenced (read or

It's up to you to define the size and data type of the array first, then to
store values in the array elements, and finally to use (read or update) the
elements by means of their index (ArrayName[IndexNumber]).

Hope this description helps you a bit :-)

  Reply With Quote
8 22nd May 02:18
External User
Posts: 1
Default Help with arrays pleas.

I think the best way to understand arrays is by string. since a string
is in reality an array of char.

Therefore understanding how strings work will enable you to understand
  Reply With Quote
9 22nd May 02:18
markus humm
External User
Posts: 1
Default Help with arrays pleas.


Of course you're right, simple typo...

Normally yes, but for a beginner I thought this would be overkill. If he
understands arrays, then he can take the next step, I think.

Yes, you're right, but that depends on this TP/BP version. Afaik High
was introduced woth TP 7, so he eventually had to use a workaround in
earlier versions.


  Reply With Quote
10 22nd May 02:18
External User
Posts: 1
Default Help with arrays pleas.

THanks for all this folks. I am using TP7. I think whare i am geting
confused when using array is that you can store so meny types of them
for very diffrent jobs but they problay will make life easyer in long
run when i finaly get my head round them. At least i understanding how
pascal works now though. I am only a beginer in this so this is of
grate use to me thanks all realy appreaciate.
  Reply With Quote

Thread Tools
Display Modes

Copyright 2006 - Dies Mies Jeschet Boenedoesef Douvema Enitemaus -