Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 Two program problems
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
hugonibs2




PostPosted: 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
if 60 < weight < 80 then
put "You are at a medium weight range"
elsif weight > 80 then
put "You are at a hevyweight weight range"
elsif weight < 60 then
put "You are at a lightweight weight range"
end if



Please specify what version of Turing you are using
4.1
Sponsor
Sponsor
Sponsor
sponsor
BigBear




PostPosted: Wed Apr 22, 2009 1:44 pm   Post subject: RE:Two program problems

Turing:
if 60 < weight < 80 then


Must be
Turing:
if weight >60 and weight <80 then


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




PostPosted: 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




PostPosted: 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
end for


it's basically a short way of doing this:

Turing:

var n : int := 1
loop
    put "This is repetition ", n
    n := n + 1
    exit when n = 10
end loop


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




PostPosted: 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 > 80 then
put "You are at a hevyweight weight range"
elsif weight < 60 then
put "You are at a lightweight weight range"
end if
end loop



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.
Display posts from previous:   
   Index -> Programming, Turing -> Turing Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 5 Posts ]
Jump to:   


Style:  
Search: