How can I make my program repeat as many times as the user wants?
Author |
Message |
turinghelp101
|
Posted: Sun Jan 08, 2012 12:29 pm Post subject: How can I make my program repeat as many times as the user wants? |
|
|
What is it you are trying to achieve?
<Replace all the <> with your answers/code and remove the <>>
I have to make a thermometer that will convert fahrenheit to celcius, display the temperature on a thermometer and on a counter. It also has to repeat as many times as the user wishes
What is the problem you are having?
<Answer Here>
I cant figure out how to make the program repeat as many times as the user wants
Describe what you have tried to solve this problem
<Answer Here>
I used the code below but it covers the whole screen when you output it. I am trying to make repeat like this: the user inputs a temperature and everything is displayed and then they can click somewhere on the screen or do somthing to make that process repeat again
Post any relevant code (You may choose to attach the file instead of posting the code if it is too long)
<Answer Here>
this is the code I used in an attempt to solve the problem but the whole program is below
var i:int
put "How many iterations?"..
get i
for :1..i
var number : int
put "Enter your temperature in farenheit"
get number
put "Your temperature in celcius is:", ((5 / 9) * number) - 32
if number >= 10 then
drawline (200, 220 + number, 300, 220 + number, 5)
end if
end for
Turing: |
<Add your code here>
|
Please specify what version of Turing you are using
<Answer Here>
I am using turing version 4.1
Description: |
|
![](http://compsci.ca/v3/pafiledb/images/icons/clip.gif) Download |
Filename: |
FINISHED COPY OF PROGRAMMING FOR ISP.T |
Filesize: |
42.36 KB |
Downloaded: |
100 Time(s) |
|
|
|
|
|
![](images/spacer.gif) |
Sponsor Sponsor
![Sponsor Sponsor](templates/subSilver/images/ranks/stars_rank5.gif)
|
|
![](images/spacer.gif) |
turinghelp101
|
Posted: Sun Jan 08, 2012 12:32 pm Post subject: Re: How can I make my program repeat as many times as the user wants? |
|
|
By the way, the program is long, but only the top is what needs to be looked at because thats where im trying to make the program repeat
|
|
|
|
|
![](images/spacer.gif) |
Beastinonyou
![](http://compsci.ca/v3/uploads/user_avatars/10820786614fe1f6d9ccbda.png)
|
Posted: Sun Jan 08, 2012 12:39 pm Post subject: Re: How can I make my program repeat as many times as the user wants? |
|
|
ok... so you want the program to loop through however many times the user wants..
how would you go about doing this, if for statements work like this
Turing: |
for i : minimum .. maximum
|
and you obtain the maximum number of iterations by doing the following:
Turing: |
var maxIterations : int := 0
put "Enter the max number of iterations you wish: " ..
get maxIterations
|
where should you use the variable: maxIterations within the first line of the for statement in order to achieve what you want?
|
|
|
|
|
![](images/spacer.gif) |
RandomLetters
|
Posted: Sun Jan 08, 2012 1:38 pm Post subject: Re: How can I make my program repeat as many times as the user wants? |
|
|
What if the user does not yet know how many times he wants to run it? What if at first, he thinks "I might want to do this 10 times", and enters 10, but then has to go after 5 iterations?
Instead of a for loop, consider a do...while loop, which runs the code inside at least once, and then repeats until a condition is later met
Of course, you can use any condition to determine when to quit.
In any case, I think the problem with your current program is just to clear the screen when you repeat, with cls
|
|
|
|
|
![](images/spacer.gif) |
|
|