Multiple variable equation problem

12 posts / 0 new
Last post
Offline
Last seen: 9 years 5 months ago
Joined: Sep 3 2014 - 21:33
Posts: 21
Multiple variable equation problem

I'd like to know how to use one input line to generate a single outcome based on a pre-assigned section of data. An example - using days, weeks, months D$(X) and dollars D(X).

=== PRESET VALUES ===
10 AA$ = “MORNING” : BB$ = “DAY” : CC$ = “NIGHT”: AC = 1000
=== INPUT LINE ===
20 INPUT “WHICH TIMEFRAME >”;TF$
30 IF TF$=1 THEN GOSUB 100 : GOTO 500
40 IF TF$=2 THEN GOSUB 200 : GOTO 500
50 IF TF$=3 THEN GOSUB 300 : GOTO 500
=== GET VARIABLES ===
(the same variable is assigned a name and a matching numeric value regardless of source list. The variable LS designates which source list the variables come from.)
100 LS = 1 : D$(1) = ”MON” : D(1) = 20 : D$(2) = ”TUE” : D(2) = 30 : D$(3) = “WED” : D(3) = 30 : RETURN
200 LS = 2 : D$(1) = “WK1” : D(1) = 100 : D$(2) = ”WK2” : D(2) = 110 : D$(3) = “WK3” : W(3) = 130 : RETURN
300 LS = 3 : D$(1) = “JAN” : D(1) = 500 : D$(2) = “FEB” : D(2) = 600 : D$(3) = “MAR” : D(3) =700 : RETURN
=== DISPLAY VARIABLES ===
500 PRINT “1) ”; D$(1) : VTAB 1 : HTAB 10 : ? D(1)
510 PRINT “2) ”; D$(2) : VTAB 2 : HTAB 10 : ? D(2)
520 PRINT “3) ”; D$(3) : VTAB 3 : HTAB 10 : ? D(3)
=== INPUT CHOICE ===
(regardless of the assigned name and matching variable I use the same input line. Well, that's what I'm hoping to achieve)
600 PRINT “CHOOSE WHICH >” : GET ZZ

My actual count is 3 lists of 11 variables per list. I can solve my problem with a ridiculous number of IF THEN statements.
IF ZZ = 1 AND LS = 1 THEN AC = AC – D(1) : AA$ = D$(1)
IF ZZ = 2 AND LS = 1 THEN AC = AC – D(2) : AA$ = D$(2)
IF ZZ = 3 AND LS = 1 THEN AC = AC – D(3) : AA$ = D$(3)
IF ZZ = 1 AND LS = 2 THEN AC = AC – D(1) : BB$ = D$(1)
IF ZZ = 2 AND LS = 2 THEN AC = AC – D(2) : BB$ = D$(2)
and so on...

Is there a simple way to do this?

Offline
Last seen: 8 years 11 months ago
Joined: Apr 10 2006 - 20:01
Posts: 1013
Re: Multiple variable equation problem

You might consider sticking to one forum (at a time) for posting a question.

http://www.vintage-computer.com/vcforum/showthread.php?44230-BASIC-Process-multiple-variables-with-one-input-line

Offline
Last seen: 9 years 5 months ago
Joined: Sep 3 2014 - 21:33
Posts: 21
Re: Multiple variable equation problem

@ David

Sure, no problem. Didn't mean to spam up different sites, but was wondering if I would get different solutions from different sites. Just putting it out there... I'll stay more concise from now on.

A big thanks to all replies and the useful information. Smile

BillO's picture
Offline
Last seen: 4 years 4 months ago
Joined: Jun 20 2014 - 18:03
Posts: 258
Re: Multiple variable equation problem

I think we could use a better description of what you are trying to achieve. Tell us the whole story. Showing us the code that does not work without that description is not all that informative.

Just 'wild' guessing though, have you considered putting all the possible responses in several 2-diemtional matrices, or even a single 3-d matrix?

Offline
Last seen: 9 years 5 months ago
Joined: Sep 3 2014 - 21:33
Posts: 21
Re: Multiple variable equation problem

Hiya. Yes, thanks. When I get it sorted I'll post what I have. It'll be maybe 20 or 30 lines though. As I'm new here I didn't want to post a large portion of code and expect others to sort it out for me.

However, I have a related question.

How can I get a batch of numeric variables to all adjust by the same number?
For example (this doesn't work, but I think you'll see what I'm trying to achieve):

10 P(1)=10 : P(2)=20: P(3)=30: P(4)=40: P(5)=50
20 INPUT Z
30 FOR A = 1 TO 5 : P(A) = P(A) - Z : NEXT
40 ?P(1) : ?P(2) : ?P(3) : ?P(4) : ?P(5)

Obviously my results are 10,20,30,40,50. How can I make a sequence of variables all adjust by the same number (IE: line 20)?

Offline
Last seen: 8 years 11 months ago
Joined: Apr 10 2006 - 20:01
Posts: 1013
Re: Multiple variable equation problem

How can I get a batch of numeric variables to all adjust by the same number?
For example (this doesn't work, but I think you'll see what I'm trying to achieve):

10 P(1)=10 : P(2)=20: P(3)=30: P(4)=40: P(5)=50
20 INPUT Z
30 FOR A = 1 TO 5 : P(A) = P(A) - Z : NEXT
40 ?P(1) : ?P(2) : ?P(3) : ?P(4) : ?P(5)

Obviously my results are 10,20,30,40,50. How can I make a sequence of variables all adjust by the same number (IE: line 20)?


What would you expect the values to be for input 5? I expect 5, 15, 25, 35, and 45 - and that's what I get with your code.

BillO's picture
Offline
Last seen: 4 years 4 months ago
Joined: Jun 20 2014 - 18:03
Posts: 258
Re: Multiple variable equation problem

When I run your code on an Apple IIe I get:

5
15
25
35
45

I'm not sure what your problem is.

Also, to your comment that you are going to supply us with 30 lines of code regarding your first question. No, that's not what I mean. I mean, give us a written explanation of the specific problem you want to solve.

Edit: Looks like David beat me to the punch.

Offline
Last seen: 9 years 5 months ago
Joined: Sep 3 2014 - 21:33
Posts: 21
Re: Multiple variable equation problem

Okay. The second issue. I have a set of pre-assigned variables. They have no relevance to each other, 60, 110, 250, 425. Or something like that. In the example I posted I used increments of ten to keep things simple.

Let's say I have a group of numbers P1=10, P2=20, P3=30, P4=40, P5=50. I want them to be adjusted by two numbers both of which are variable, ZZ and PS. ZZ and PS are affected by user input. As part of a game when the user performs actions ZZ and PS change independently. In other words when the user does one thing ZZ changes. When they do another PS changes. P1 to P11 then need to be adjusted by the figure obtained by dividing ZZ by PS.

To get the variable adjustment I use A= INT (ZZ/PS).

I am stuck as to what to do next. All the P1 to P11 variables need to be adjusted by A. Is there a way to do this without individually programming:
P1 = P1-A : P2 = P2-A : P3 = P3-A and so on.

I apologise if I am not accurately conveying my programming issues, but I do appreciate your comments.

If you could provide an example of a solution that would be of much assistance rather than just say use a FOR/NEXT loop or a DATA statement.

Thanks.

Offline
Last seen: 8 years 11 months ago
Joined: Apr 10 2006 - 20:01
Posts: 1013
Re: Multiple variable equation problem

All the P1 to P11 variables need to be adjusted by A. Is there a way to do this without individually programming:
P1 = P1-A : P2 = P2-A : P3 = P3-A and so on.

If they're individual variable names, then no, there's no way to adjust them all without programming each one. if the P variables were actually an array, though, you could do them in a loop:

for i = 1 to 11:P(i)=P(i)-A:next i

BillO's picture
Offline
Last seen: 4 years 4 months ago
Joined: Jun 20 2014 - 18:03
Posts: 258
Re: Multiple variable equation problem

Here is another take on it. This sample uses an array as David suggested and also uses DATA and READ to set up the initial values in the array.

9 REM
10 REM READ INITIAL VALUES - DATA IN LINE 130
11 REM
20 FOR I = 0 TO 10:READ V(I):NEXT I
30 PRINT"VALUES BEFORE CHANGES:"
40 FOR i=0 TO 10:PRINT" ";V(I):NEXT I:PRINT
44 REM
45 REM SUBTRACT ENTERED VALUE ZZ
46 REM
50 INPUT "ENTER SUBTRACT VALUE ";ZZ
60 FOR I= 0 TO 10:V(I)=V(I)-ZZ:NEXT I
70 PRINT"VALUES AFTER SUBTRACTION:"
80 FOR i=0 TO 10:PRINT" ";V(I):NEXT I:PRINT
84 REM
85 REM ADD ENTERED VALUE YY
86 REM
90 INPUT "ENTER ADD VALUE ";YY
100 FOR I= 0 TO 10:V(I)=V(I)+YY:NEXT I
110 PRINT"VALUES AFTER ADDING:"
120 FOR I=0 TO 10:PRINT" ";V(I):NEXT I:PRINT
124 REM
125 REM INITIAL VALUES
126 REM
130 DATA 34,45,123,61,22,33,87,90,41,4,57

Offline
Last seen: 9 years 5 months ago
Joined: Sep 3 2014 - 21:33
Posts: 21
Re: Multiple variable equation problem

Thanks for those comments. I can see applications for both solutions. Especially in regard to keeping file size down with lots of lines of programming.

I'm pretty sure your advice is going to solve my initial query as well... which I created a screenshot for. Now, let me see if I can attach it.

[inline:attached_image_#]
Right, that didn't work. How about...

http://www.applefritter.com/content/rockbadger-weapons-capture

The problem was having multiple lists like this. In this list weapon1 is P1$. In the shields list shield 1 is also P1$. and so on through 11 different weapons, shields or armour.

Using your coding will work for lines 2200-2300, right?

Offline
Last seen: 8 years 11 months ago
Joined: Apr 10 2006 - 20:01
Posts: 1013
Re: Multiple variable equation problem


Using your coding will work for lines 2200-2300, right?

Exactly. Your PE index serves as the index for what's bought, as well as how much it costs (which will have to be a new array that holds the cost of each weapon).

Log in or register to post comments