Dathor Verlox
07-01-2003, 03:00 PM
I havent used JavaScript much but I was planning on using it to replicate a program I wrote in Liberty BASIC. Is it possible to "goto" a set location for example, if one variable equals another you skip a chunk of code and go on to the next bit?
I have added the Liberty BASIC code I am attempting to replicate below. It calculates the PMCC for the values entered with a maximum of ten sets of data.
[start]
input "How many sets of values do you have? "; sets
let setscount = 0
if sets = 0 then [help]
[xvalues]
input "Enter the first x value. "; xone
let setscount = setscount + 1
if setscount = sets then [yvalues]
input "Enter the next x value. "; xtwo
let setscount = setscount + 1
if setscount = sets then [yvalues]
input "Enter the next x value. "; xthree
let setscount = setscount + 1
if setscount = sets then [yvalues]
input "Enter the next x value. "; xfour
let setscount = setscount + 1
if setscount = sets then [yvalues]
input "Enter the next x value. "; xfive
let setscount = setscount + 1
if setscount = sets then [yvalues]
input "Enter the next x value. "; xsix
let setscount = setscount + 1
if setscount = sets then [yvalues]
input "Enter the next x value. "; xseven
let setscount = setscount + 1
if setscount = sets then [yvalues]
input "Enter the next x value. "; xeight
let setscount = setscount + 1
if setscount = sets then [yvalues]
input "Enter the next x value. "; xnine
let setscount = setscount + 1
if setscount = sets then [yvalues]
input "Enter the next x value. "; xten
let setscount = setscount + 1
if setscount = sets then [yvalues]
[yvalues]
let setscount = 0
input "Enter the first y value. "; yone
let setscount = setscount + 1
if setscount = sets then [calc]
input "Enter the next y value. "; ytwo
let setscount = setscount + 1
if setscount = sets then [calc]
input "Enter the next y value. "; ythree
let setscount = setscount + 1
if setscount = sets then [calc]
input "Enter the next y value. "; yfour
let setscount = setscount + 1
if setscount = sets then [calc]
input "Enter the next y value. "; yfive
let setscount = setscount + 1
if setscount = sets then [calc]
input "Enter the next y value. "; ysix
let setscount = setscount + 1
if setscount = sets then [calc]
input "Enter the next y value. "; yseven
let setscount = setscount + 1
if setscount = sets then [calc]
input "Enter the next y value. "; yeight
let setscount = setscount + 1
if setscount = sets then [calc]
input "Enter the next y value. "; ynine
let setscount = setscount + 1
if setscount = sets then [calc]
input "Enter the next y value. "; yten
let setscount = setscount + 1
if setscount = sets then [calc]
[calc]
let xbar = (xone + xtwo + xthree + xfour + xfive + xsix + xseven + xeight + xnine + xten)/sets
let ybar = (yone + ytwo + ythree + yfour + yfive + ysix + yseven + yeight + ynine + yten)/sets
let sumxy = (xone*yone)+(xtwo*ytwo)+(xthree*ythree)+(xfour*yfour)+(xfive*yfive)+(xsix*ysix)+(xseven*yseven)+(xei ght*yeight)+(xnine*ynine)+(xten*yten)
let sumx = xone + xtwo + xthree + xfour + xfive + xsix + xseven + xeight + xnine + xten
let sumy = yone + ytwo + ythree + yfour + yfive + ysix + yseven + yeight + ynine + yten
let sumxsumy = sumx*sumy
let sumxsq = (xone^2)+(xtwo^2)+(xthree^2)+(xfour^2)+(xfive^2)+(xsix^2)+(xseven^2)+(xeight^2)+(xnine^2)+(xten^2)
let sumysq = (yone^2)+(ytwo^2)+(ythree^2)+(yfour^2)+(yfive^2)+(ysix^2)+(yseven^2)+(yeight^2)+(ynine^2)+(yten^2)
let sumxallsq = sumx^2
let sumyallsq = sumy^2
let bottomxbrac = sumxallsq/sets
let bottomybrac = sumyallsq/sets
let bottomx = sumxsq-bottomxbrac
let bottomy = sumysq-bottomybrac
[answer]
let top = sumxy-(sumxsumy/sets)
let bottom = bottomx*bottomy
let rootbottom = SQR(bottom)
let pmcc = top/rootbottom
print
print "The PMCC of the numbers you entered is: "; pmcc
[rerun]
input "Run again? (Enter yes or no) ";rerun$
if rerun$ = "yes" then [start]
end
[help]
print "This program calculates the PMCC of the numbers entered."
print "First enter the number of x and y values you have and then"
print "enter the x and y values themselves. You must enter more than"
print "one set of data."
print
print "This program was made by Harry Mills for free distribution."
print
Sorry its long but I have only just started programming so I dont know any other way. (Could you do it with arrays maybe?)
If you know any way I can either shorten the code or neaten it up please tell me.
Thanks
I have added the Liberty BASIC code I am attempting to replicate below. It calculates the PMCC for the values entered with a maximum of ten sets of data.
[start]
input "How many sets of values do you have? "; sets
let setscount = 0
if sets = 0 then [help]
[xvalues]
input "Enter the first x value. "; xone
let setscount = setscount + 1
if setscount = sets then [yvalues]
input "Enter the next x value. "; xtwo
let setscount = setscount + 1
if setscount = sets then [yvalues]
input "Enter the next x value. "; xthree
let setscount = setscount + 1
if setscount = sets then [yvalues]
input "Enter the next x value. "; xfour
let setscount = setscount + 1
if setscount = sets then [yvalues]
input "Enter the next x value. "; xfive
let setscount = setscount + 1
if setscount = sets then [yvalues]
input "Enter the next x value. "; xsix
let setscount = setscount + 1
if setscount = sets then [yvalues]
input "Enter the next x value. "; xseven
let setscount = setscount + 1
if setscount = sets then [yvalues]
input "Enter the next x value. "; xeight
let setscount = setscount + 1
if setscount = sets then [yvalues]
input "Enter the next x value. "; xnine
let setscount = setscount + 1
if setscount = sets then [yvalues]
input "Enter the next x value. "; xten
let setscount = setscount + 1
if setscount = sets then [yvalues]
[yvalues]
let setscount = 0
input "Enter the first y value. "; yone
let setscount = setscount + 1
if setscount = sets then [calc]
input "Enter the next y value. "; ytwo
let setscount = setscount + 1
if setscount = sets then [calc]
input "Enter the next y value. "; ythree
let setscount = setscount + 1
if setscount = sets then [calc]
input "Enter the next y value. "; yfour
let setscount = setscount + 1
if setscount = sets then [calc]
input "Enter the next y value. "; yfive
let setscount = setscount + 1
if setscount = sets then [calc]
input "Enter the next y value. "; ysix
let setscount = setscount + 1
if setscount = sets then [calc]
input "Enter the next y value. "; yseven
let setscount = setscount + 1
if setscount = sets then [calc]
input "Enter the next y value. "; yeight
let setscount = setscount + 1
if setscount = sets then [calc]
input "Enter the next y value. "; ynine
let setscount = setscount + 1
if setscount = sets then [calc]
input "Enter the next y value. "; yten
let setscount = setscount + 1
if setscount = sets then [calc]
[calc]
let xbar = (xone + xtwo + xthree + xfour + xfive + xsix + xseven + xeight + xnine + xten)/sets
let ybar = (yone + ytwo + ythree + yfour + yfive + ysix + yseven + yeight + ynine + yten)/sets
let sumxy = (xone*yone)+(xtwo*ytwo)+(xthree*ythree)+(xfour*yfour)+(xfive*yfive)+(xsix*ysix)+(xseven*yseven)+(xei ght*yeight)+(xnine*ynine)+(xten*yten)
let sumx = xone + xtwo + xthree + xfour + xfive + xsix + xseven + xeight + xnine + xten
let sumy = yone + ytwo + ythree + yfour + yfive + ysix + yseven + yeight + ynine + yten
let sumxsumy = sumx*sumy
let sumxsq = (xone^2)+(xtwo^2)+(xthree^2)+(xfour^2)+(xfive^2)+(xsix^2)+(xseven^2)+(xeight^2)+(xnine^2)+(xten^2)
let sumysq = (yone^2)+(ytwo^2)+(ythree^2)+(yfour^2)+(yfive^2)+(ysix^2)+(yseven^2)+(yeight^2)+(ynine^2)+(yten^2)
let sumxallsq = sumx^2
let sumyallsq = sumy^2
let bottomxbrac = sumxallsq/sets
let bottomybrac = sumyallsq/sets
let bottomx = sumxsq-bottomxbrac
let bottomy = sumysq-bottomybrac
[answer]
let top = sumxy-(sumxsumy/sets)
let bottom = bottomx*bottomy
let rootbottom = SQR(bottom)
let pmcc = top/rootbottom
print "The PMCC of the numbers you entered is: "; pmcc
[rerun]
input "Run again? (Enter yes or no) ";rerun$
if rerun$ = "yes" then [start]
end
[help]
print "This program calculates the PMCC of the numbers entered."
print "First enter the number of x and y values you have and then"
print "enter the x and y values themselves. You must enter more than"
print "one set of data."
print "This program was made by Harry Mills for free distribution."
Sorry its long but I have only just started programming so I dont know any other way. (Could you do it with arrays maybe?)
If you know any way I can either shorten the code or neaten it up please tell me.
Thanks