Posted: Wed Apr 22, 2009 8:32 am Post subject: Two program problems
What is it you are trying to achieve?
I am trying to create a program that will sort the players into weight catagories.
What is the problem you are having?
I have two problems in this program.
The first
I would like to loop it with the variable that is entered in players. Is this possible?
the second problem
how would i fix this line
if 60 < weight < 80 then
I would like for it to choose this statement if the weight is bigger than 60 but less then 80.
Turing:
loop var weight :real var players :int
put"How many players are on your team? "..
get players
put"please enter your weight in kg: "..
get weight
if60 < weight < 80then put"You are at a medium weight range" elsif weight > 80then put"You are at a hevyweight weight range" elsif weight < 60then put"You are at a lightweight weight range" endif
Please specify what version of Turing you are using
4.1
Sponsor Sponsor
BigBear
Posted: Wed Apr 22, 2009 1:44 pm Post subject: RE:Two program problems
Turing:
if60 < weight < 80then
Must be
Turing:
if weight >60and weight <80then
Also to get a variable in a loop you need to declare the variable outside the loop and then just use the get command
Calling a variable in a loop is bad coding because it creates a variable every time and you can no longer access the previous variables created so they are useless.
Also if you want to check the value of the variable it can be nothing.
hugonibs2
Posted: Thu Apr 23, 2009 7:16 am Post subject: RE:Two program problems
Do you know if i is possible for me to loop according to the number that is entered in players
TheGuardian001
Posted: Thu Apr 23, 2009 3:28 pm Post subject: Re: Two program problems
I believe you are looking for for loops
a for loop will take a section of code and run it a specified number of times.
Turing:
for i :1.. 10 put"This is repetition ", i
endfor
it's basically a short way of doing this:
Turing:
var n :int:=1 loop put"This is repetition ", n
n := n + 1 exitwhen n =10 endloop
i can be replaced with anything you want, as long as it is not already being used. It's just a temporary variable.
1 .. 10 you can use integers or variables for these two values. it basically just tells Turing how many times to run a section of code. this one runs 10 time.
tjmoore1993
Posted: Thu Apr 23, 2009 7:55 pm Post subject: RE:Two program problems
Turing:
loop var weight :real
put"please enter your weight in kg: "..
get weight
if(60 < weight and weight < 80)then put"You are at a medium weight range" elsif weight > 80then put"You are at a hevyweight weight range" elsif weight < 60then put"You are at a lightweight weight range" endif endloop
I excluded the following code from the project.
Turing:
var players :int
put"How many players are on your team? "..
get players
You did not give a specific purpose for this so I decided to remove it.