Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

2d arrays

Status
Not open for further replies.

qbiscool

Programmer
Feb 18, 2004
33
CA
can you store info from a user in a 2d array and then add two numbers together.
 
Could you please elabourate? I read your question and it almost sounds like you mean a 2 element 1 dimensional array...

and that would be...

dim nums(1 to 2)

for a = 1 to 2 ' this is unnessesary
input nums(a)
next a
result = 0
for a = 1 to 2 ' this is really unnessesary. It's embarassing.
result = result + nums(a)
next a

print "the result is ";result

...but...
 
a 2d array would be like DIM array(5,5) - do you mean adding two of those together like matrix addition?

[4,4] + [1,0] = [4,4]
[5,3] [0,1] [5,3]



if a line is unnessasary then why write it, you FOR-NEXT loop is actually more code and slower than just doing
result = result + nums(a)
result = result + nums(b)
 
qbasicking is right. but i need to no how to add a 2d array like this

dim n(3,3)

x = n(3+3)
' i no this is wrong but its the only to describe it


and id also like to no how to display just one of the two
arrays like:

dim n(4,2)

print n(3, ) ' just show the first one

 
Is this what you mean?

Code:
DIM Test(1, 2)
CLS

Test(1, 1) = 5
Test(1, 2) = 15
Test(1, 0) = Test(1, 2) + Test(1, 1)
FOR Cycle = 2 TO 0 STEP -1
     PRINT "Test (1," + STR$(Cycle) + ") = ",
     PRINT Test(1, Cycle)
NEXT Cycle
print "----------------" : Print
sleep 4

Test(0, 1) = 3
Test(0, 2) = 4
FOR Cycle = 1 TO 2
     PRINT "Test (0," + STR$(Cycle) + ") = ",
     PRINT Test(0, Cycle)
NEXT Cycle
Test(0, 0) = Test(0, 2) + Test(0, 1)
PRINT Test(0, 0)
print "----------------" : Print
sleep 4

print "combined total of Temp(0,0) + Temp(1,0);"
print
print Test(0,0) + Test(1,0)
END

Is this what you are talking about?
--MiggyD
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top