BASIC LANGUAGE HOMEWORK QUESTION!!!!! HELP

Status
Not open for further replies.
I have to write a program that calls up to Dim statements, one is a string and one is a variable. I have to store names in one and then Golf scores in the other. then I have a nested loop where they enter their scores, then at the end I have to add them up and then display them.

HOW DO I ADD THEM???? This homework is due tommorrow and I need any kind of help. I will post what I have done in a few minutes, my laptop is booting now.
 
OPTION NOLET
DIM name$(10)
DIM score(20,20)
PRINT "Welcome to the GOLFERS AIDE"
PRINT
PRINT
PRINT "How many people will be playing?"
INPUT players
PRINT "Please insert names:"
FOR P = 1 to players step 1
INPUT name$(P)
NEXT P
PRINT "How many holes will be played?"
INPUT holes
FOR U = 1 to holes
PRINT
PRINT
PRINT "Hole";U
FOR Y= 1 to players
INPUT score(Y,U)
NEXT y
NEXT U
END


This is what I have as of right now
 

wb

Ars Legatus Legionis
25,208
Subscriptor
It looks like you're using BASIC from about 20 years ago. You know there are better versions around nowadays, right?

I don't normally do this, but here's how you add them up. I would have thought that if you could figure out how to store all the data with a nested loop, you'd be able to figure out how to add them all up, but perhaps your teacher didn't explain this properly. Please note that I'm not sure if the code will work correctly in your version of basic, so you'll probably have to modify it a little bit.

Code:
dim sum
dim h
rem mmmmmm.... dim sum
for p = 1 to players
   sum = 0
   for h = 1 to holes
      sum = sum + score(p,h)
   next h
   print "Player " & name$(p) & "'s total score = " & sum
next p
 
dim sum
dim h
rem mmmmmm.... dim sum
for p = 1 to players
sum = 0
for h = 1 to holes
sum = sum + score(p,h)
next h
print "Player " & name$(p) & "'s total score = " & sum
next p

thanks I do have to modify it for the version of BASIC that I have, but I will try and use it.

HANDOR

I'm really confused. If I understand what you said, it seems like you want me to go through one player at a time, and ask for the scores for the all the holes and then move on to the next player??? Sorry, I've been doing a lot of homework and my brain is fried and that is a lot of text. I'm reading it again to see if I can understand this.

Edit - Ummm....Why did you get rid of it?
 

Handor

Ars Tribunus Militum
2,513
No, there's actually a better way to do it, even with the looping structure you were advocating. What I was explaining (the less-optimal method) was basically what was posted above, so I removed it.

The more optimal way can simply use your existing looping structure and, as soon as you get done with it, you're already finished with everything. Basically, it eliminates the second pass. But in order to do it, you have to be slightly more tricky with your methods.

Sorry to be confusing. The way wb did it was perfectly acceptable-- just not as 1337. ;)

So anyway, never mind. You're fine. I only deleted my post because it was a) redundant, and b) I think it used syntax from a different version of BASIC than you were using.
 
Status
Not open for further replies.