Page 1 of 1

cycle for

PostPosted: 20 Jul 2015, 10:53
by mark
Hello to all guys .. I ask my help in solving this problem. I write the code and then requests that I would get
Code: Select all
Prgm
Dialog
Request "N.corpi",aux
EndDlog
expr(aux)->aux
For i,1,aux,1
............................??????
Dialog
Request "M",aux1
Request "V",aux2
EndDlog
expr(aux1)->aux1
expr(aux2)->aux2
Pause aux1*aux2
EndFor
EndPrgm


The calculator asks me how many are the bodies and according to the number of bodies, the calculator executes the loop. Suppose that the bodies are 2, then the cycle will be repeated for 2 times.
It will be like this:


N. Corpi 2

M= 3
V= 8

I want to see screen 3 * 8 = 24


M= 5
V= 2


I want to see screen 5 * 2 = 10

I can not save in a variable 3 * 8 = 24 and 5 * 2 = 10

Can anyone help me?
thanks a lot
mark

Re: cycle for

PostPosted: 20 Jul 2015, 11:00
by critor
Hi!

You could try this output line :
Code: Select all
Pause string(aux1)&"*"&string(aux2)&"="&string(aux1*aux2)

Re: cycle for

PostPosted: 20 Jul 2015, 11:28
by mark
Thanks but I wanted something like this:
3*8=24 --> asd
5*2=10 --> ads
how could I do?

Re: cycle for

PostPosted: 20 Jul 2015, 12:24
by critor
Then store instead of displaying ?
Code: Select all
string(aux1)&"*"&string(aux2)&"="&string(aux1*aux2)->asd

Re: cycle for

PostPosted: 20 Jul 2015, 12:44
by mark
If the bodies were 3 and 2 what you have written is not good.I do not know in advance whether the bodies that I have to enter are 2, 3, 4 or 5 etc ...

Re: cycle for

PostPosted: 20 Jul 2015, 17:47
by Adriweb
I suppose you could store the results in a list (called tmp, in the example), and do something like this, inside of a loop at the end of your program:
Code: Select all
string(tmp[idx1])&"*"&string(tmp[idx2])&"="&string(tmp[idx1]*tmp[idx2])->asd

That also assume you know the indices for each (idx1 and idx2) - which is something you should know.

But it's less easy than printing things within the loop like Critor proposed first - you'd just have not to print anything else in between.

Re: cycle for

PostPosted: 20 Jul 2015, 18:03
by mark
OK thank you very much :)

Re: cycle for

PostPosted: 25 Jul 2015, 13:53
by mark
Code: Select all
()
Prgm

Lbl top
ClrIO
Dialog
Title "Corpi"
Text "# Corpi?"
Request "N=",nv,0
Text "Ex: N=3"
EndDlog
If ok=0:Goto quit

Disp "#Corps="&nv

expr(nv)n
newList(n)ls
newList(n)ls2

For i,1,n
Input "M"&string(i)&"=",tmp
tmpls[i]
Input "V"&string(i)&"=",tmp
tmpls2[i]
EndFor

Pause "M="&string(ls)
Pause "V="&string(ls2)
Pause "M*V="&string(ls*ls2)

For i,1,n
Pause "M"&string(i)&"*V"&string(i)&"="&string(ls[i])&"*"&string(ls2[i])&"="&string(ls[i]*ls2[i])
EndFor


EndPrgm



I took your advice, but now I do not know how to store it in a variable that I see on the screen .... That is, if

N.Corpi = 3

How to save it in the variable asd?

M1*V1+M2*V2+M3*V3 --> asd and save it in the variable asd