simple looping questions using turing
Author |
Message |
xSeasonx
|
Posted: Wed Nov 17, 2010 10:53 pm Post subject: simple looping questions using turing |
|
|
i need help on 6b (view attactment)
i have to use one FOR loop to make the chart
so its the output looks like this
number square number square
1 1 21 441
2 4 22 484
3 9 23 529
... ... ... ...
20 400 40 1600
as for number it has to go from 1-80
and the square is jsut the square of the number
i need to make 4 rows of number/square
1 row = number and square
20 numbers in each column
thanks
Description: |
|
Filesize: |
128.35 KB |
Viewed: |
324 Time(s) |
|
|
|
|
|
|
|
Sponsor Sponsor
|
|
|
xSeasonx
|
Posted: Thu Nov 18, 2010 7:45 am Post subject: RE:simple looping questions using turing |
|
|
bump! anybody! please help me
thanks
|
|
|
|
|
|
TheGuardian001
|
Posted: Thu Nov 18, 2010 2:11 pm Post subject: Re: simple looping questions using turing |
|
|
We aren't going to do it for you. What have you tried, and what isn't working?
|
|
|
|
|
|
xSeasonx
|
Posted: Thu Nov 18, 2010 5:59 pm Post subject: RE:simple looping questions using turing |
|
|
i got it to work to go from 1-20 and square the number.
but i dont know how to "Start" a new row using numbers 21-40 and then squaring them.
heres the code i got. for turing
put repeat ("Num\tSquare\t",4)
for d : 1 .. 20
put d, "\t", d * d
end for
|
|
|
|
|
|
TerranceN
|
Posted: Thu Nov 18, 2010 6:07 pm Post subject: RE:simple looping questions using turing |
|
|
Well what is the relationship between the two columns?
1-->21
2-->22
3-->23
4-->24
5-->25
6-->26
7-->27
8-->28
9-->29
In other words what do you have to do to a number in the first column to get the corresponding number in the second column?
|
|
|
|
|
|
xSeasonx
|
Posted: Thu Nov 18, 2010 6:19 pm Post subject: RE:simple looping questions using turing |
|
|
square it .
number square
1-->1
2-->4
3-->9
so far i got this code now.
put repeat ("Num\tSquare\t",5)
for d : 1 ..80
put d,"\t",d*d,"\t"..
end for
i want it like this
but my number goes like for example 1-10 ..
they go horizontal .. but i want them to go vertical
so like how it looks like in the attachment.
number-->square-->number---->square
1---space--------> 1--space->21----->441
.----space-----> .---space-->------space->
.
.
.
20---space--->400--space->40-space-->1600
|
|
|
|
|
|
TerranceN
|
Posted: Thu Nov 18, 2010 6:43 pm Post subject: RE:simple looping questions using turing |
|
|
When I said the two columns, I was referring to the ones I had posted, this will be relevant, but first...
You can ONLY print rows of output, and after you move on to the next line, you cannot go back (well, in Turing you can using the Locate command, but that is not the way this was intended to be solved). So when you write the first row of text you would have to write 1, 1?, 21, 21?, 41, 41?, 61, and 61? all before you went on to the next row. That is why it is important to see how d is related to the third, fifth, and seventh columns, so that you can anticipate what values those would be.
Finally, your for loop will only need to go until 20, instead of 80.
|
|
|
|
|
|
xSeasonx
|
Posted: Thu Nov 18, 2010 6:46 pm Post subject: RE:simple looping questions using turing |
|
|
as i said above ..
the 1st set of data.
is number ----space>square
here is the code
put repeat ("Num\tSquare\t",4)
for d : 1 .. 20
put d, "\t", d * d
end for
i got it up to there.
then i dont know/understand how to go to the next set of number and square
starting with the number 21 then end at 40
the etc. again for 41-60
sorry if i confused you
|
|
|
|
|
|
Sponsor Sponsor
|
|
|
TerranceN
|
Posted: Thu Nov 18, 2010 7:21 pm Post subject: RE:simple looping questions using turing |
|
|
Well you know your put command already has d and d squared, and is going to have to also have some number and that number squared. You know on that first line it is 1 and 21, so that number is actually d+20, so its square would be (d+20)*(d+20), so when you put that in your code you output line would be
put d, "\t", d*d, "\t", d+20, "\t", (d+20)*(d+20)
You know each line is also going to have more numbers and their squares, and on the first line they are 41, and 61. From seeing the previous example, how are these numbers and d related? And how would you put that into your code?
|
|
|
|
|
|
xSeasonx
|
Posted: Thu Nov 18, 2010 7:37 pm Post subject: RE:simple looping questions using turing |
|
|
THANKS
why didnt i think of that 0.o
anyways i took your code example and applied it to my program.
and it works now
heres the code for you to confirm
put repeat ("Num\tSquare\t", 4)
for d : 1 .. 20
put d, "\t", d * d, "\t", d + 20, "\t", (d + 20) * (d + 20),"\t", d + 40, "\t", (d + 40) * (d + 40),"\t", d + 60, "\t", (d + 60) * (d + 60)
end for
but... for the put statement.. its really long.
do you think there is another way to make the same output but shorter?
|
|
|
|
|
|
TerranceN
|
Posted: Thu Nov 18, 2010 7:49 pm Post subject: RE:simple looping questions using turing |
|
|
I did not know this until today (as I thought turing detected the end of a statement when it reached the end of a line), but you can split that line up into multiple lines, for example:
Turing: |
put d, "\t", d * d,
"\t",
d + 20, "\t", (d + 20) * (d + 20),
"\t",
d + 40, "\t", (d + 40) * (d + 40),
"\t",
d + 60, "\t", (d + 60) * (d + 60)
|
But it can be anyway you want.
|
|
|
|
|
|
xSeasonx
|
Posted: Thu Nov 18, 2010 8:18 pm Post subject: RE:simple looping questions using turing |
|
|
hey thanks
i was around other threads looking for something like tis
and there it was. ur last post was the same layout as the other thread i was reading from
thanks a million times
|
|
|
|
|
|
|
|