
-----------------------------------
turinghelp101
Sun Jan 08, 2012 12:29 pm

How can I make my program repeat as many times as the user wants?
-----------------------------------
What is it you are trying to achieve?

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?

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

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)

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






Please specify what version of Turing you are using


I am using turing version 4.1

-----------------------------------
turinghelp101
Sun Jan 08, 2012 12:32 pm

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

-----------------------------------
Beastinonyou
Sun Jan 08, 2012 12:39 pm

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


     for i : minimum .. maximum


and you obtain the maximum number of iterations by doing the following: 


     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?

-----------------------------------
RandomLetters
Sun Jan 08, 2012 1:38 pm

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


loop
   cls

   %program

   var repeat := char
   put "Press (r) to repeat"
   getch repeat
   exit when repeat != 'r'
end loop


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 [tdoc]cls[/tdoc]
