Computer Science Canada

How do I get turing to repeat a string a certain amount of times?

Author:  gayden [ Thu Feb 19, 2015 10:41 am ]
Post subject:  How do I get turing to repeat a string a certain amount of times?

So, I have an assignment in a beginner's compsci class where we have to write a program that asks the user to enter a word, and then the program will repeat the word for as many times as it has characters.

I know I need to use length (x) to get the number of times, but how do I get it to loop x times? Or how do I use a statement such as for i : 1 .. length(x) to output a string instead of numbers?

Author:  Tony [ Thu Feb 19, 2015 1:26 pm ]
Post subject:  Re: How do I get turing to repeat a string a certain amount of times?

gayden @ Thu Feb 19, 2015 10:41 am wrote:
how do I use a statement such as for i : 1 .. length(x) to output a string instead of numbers?

Sounds like you are already familiar with all the required pieces, and just need to give it a try. How do you output numbers that you've mentioned above?

Author:  gayden [ Fri Feb 20, 2015 12:17 am ]
Post subject:  Re: How do I get turing to repeat a string a certain amount of times?

Tony @ Thu Feb 19, 2015 1:26 pm wrote:
gayden @ Thu Feb 19, 2015 10:41 am wrote:
how do I use a statement such as for i : 1 .. length(x) to output a string instead of numbers?

Sounds like you are already familiar with all the required pieces, and just need to give it a try. How do you output numbers that you've mentioned above?

I believe I am, but I'm not sure how to actually utilize it.

And what do you mean by that? Like, how do you output a number you mentioned earlier in the program?
(if so, use a variable, get x, put x, etc.)

Author:  Insectoid [ Fri Feb 20, 2015 2:33 am ]
Post subject:  RE:How do I get turing to repeat a string a certain amount of times?

Everything inside a for loop executes a certain number of times. You've got all the pieces already, you just need to put them together. We really can't give you any more hints without giving away the entire answer.

Author:  gayden [ Fri Feb 20, 2015 9:48 am ]
Post subject:  Re: RE:How do I get turing to repeat a string a certain amount of times?

Insectoid @ Fri Feb 20, 2015 2:33 am wrote:
Everything inside a for loop executes a certain number of times. You've got all the pieces already, you just need to put them together. We really can't give you any more hints without giving away the entire answer.

I think I've got it, this is what I put:
code:
var word : string
put "Please enter a word: " ..
get word
for i : 1 .. length (word)
    put word
end for

Author:  Tony [ Fri Feb 20, 2015 1:34 pm ]
Post subject:  RE:How do I get turing to repeat a string a certain amount of times?

Looks good to me.


: