Qbasicnews.com
September 28, 2021, 02:45:51 PM
 Pages: [1]
 Author Topic: In need of help with parallel arrays  (Read 7296 times)
bridgettelott
New Member

Posts: 2

 « on: November 06, 2009, 01:48:26 AM »

Hey Everyone!

I'll start by saying that I'm NOT looking for help on a homework assignment. I'm taking a class that basically teaches the logic behind programming. It doesn't teach a specific language, but we use QBASIC to write beginning programs. I understand how to write pseudocode with parallel arrays. However, I don't know how to properly format them for QBASIC. I was just wondering if someone would respond to this message with a couple of parallel arrays and a brief explanation about the individual components.

Have a wonderful day!

~Bridgette~
 Logged

Live, Love, Laugh
Clippy
Member

Posts: 84

 « Reply #1 on: November 06, 2009, 05:20:21 AM »

What is a parallel array? Do you mean a string array for a name and a integer array for the age or something like that?

Let's go with that....

DIM Names(100)
DIM Ages(100)

So now you have two arrays that can hold 100 names and ages.

Now all you have to do is fill the array element values in the program.

1) Get the data from a user entry
2) Get data from the program using DATA field
3) Get data from a file

The array elements should match the data supplied.

So If I enter "Ted" for the name and 50 for my age, then :

PRINT Names(1) ' displays Ted

PRINT Ages(1) ' displays 50

You can create other arrays for different number types.
 Logged

bridgettelott
New Member

Posts: 2

 « Reply #2 on: November 06, 2009, 06:20:57 PM »

Hi Clippy!

Thanks for responding to my post! According to my textbook, parallel arrays refer to two corresponding arrays where each element in one array is associated with the element in the same relative position in the other array. Your example definitely fits as a parallel array. I was confused about how an association was made between the two elements in different arrays. Now, I can see its the number in the () that forms the association. I'm learning slowly, but surely ... I greatly appreciate your help!

Have a blessed day!

~Bridgette~
 Logged

Live, Love, Laugh
Clippy
Member

Posts: 84

 « Reply #3 on: November 07, 2009, 07:24:08 PM »

OOPS I forgot to define the Array types:

DIM Names(100) AS STRING
DIM Ages(100) AS INTEGER
 Logged

 Pages: [1]