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

Username:   Password: 
 RegisterRegister   
 "Elsif" All of them can be true, how do you diffrentiate?
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
alex12342011




PostPosted: Fri May 14, 2010 10:38 pm   Post subject: "Elsif" All of them can be true, how do you diffrentiate?

What is it you are trying to achieve?

I am trying to create a program that asks the user to enter a temperature in degrees Celsius. Using an if-then-else structure to print a message based on the following ranges:
below 18 very cold
18 or below 0 cold
0 freezing point of water
above 0 to 10 very cool
11 to 20 moderate
21 to 30 warm
31 to 40 hot
41 to 99 extremely hot
100 boiling point of water


What is the problem you are having?


But... my program just tells me "very cool" for everything over 0.



Post any relevant code (You may choose to attach the file instead of posting the code if it is too long)

Turing:


var t : real
var reply : string (1)

put "This program will describe the temperature of the environment."
locate (3, 8)
put "Please press any key to continue."
getch (reply)
cls


put "Please enter the temperature in degrees celsius."
get t

if t < -18 then
put "Very cold!"
elsif t < 0 then
put "Cold"
elsif t = 0 then
put "Freezing point of water"
elsif t > 0 or t = 10 then
put "Very cool"
elsif t > 11 or t = 11 then
put "Moderate"
elsif t > 21 or t = 21 then
put "Warm"
elsif t > 31 or t = 31 then
put "Hot"
elsif t > 41 or t = 41 then
put "Extremely hot!"
elsif t = 100 then
put "Boiling point of water"

end if




Please specify what version of Turing you are using
I am using version 4.05 of turing.


BTW I've read the tutorial on the if statements, maybe I missed something? Thanks for any replies in advance, appreciate the help.
Sponsor
Sponsor
Sponsor
sponsor
TheGuardian001




PostPosted: Fri May 14, 2010 10:57 pm   Post subject: Re: "Elsif" All of them can be true, how do you diffrentiate?

Read you statements out as if they were a sentence. For example, your first condition with an or, as a sentance:
code:

If the temperature is above 0, or the temperature is 10, say it's "Very cool."

Based on that, would you say "Very cool" if I told you the temperature was 20 degrees?

You are currently using or. This means that if either condition is true (doesn't have to be both), the entire thing is true. You probably want to use and, since you want both to be true. So even if temperature isn't 10, so long as temperature is > 0, the entire thing is considered true.

Oh, and you shouldn't be using =. That's a definite value, not a range.
alex12342011




PostPosted: Fri May 14, 2010 11:31 pm   Post subject: Re: "Elsif" All of them can be true, how do you diffrentiate?

How do you input ranges? I'm new at this so pardon me.
-thanks
Tony




PostPosted: Sat May 15, 2010 12:29 am   Post subject: RE:"Elsif" All of them can be true, how do you diffrentiate?

You describe a range with a lower bound and an upper bound.
code:

if t > 10 and t < 20 then ...

It's important to understand how
code:

if t > 10 or t < 20 then ...

evaluates to true for any number.
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
alex12342011




PostPosted: Sat May 15, 2010 8:52 pm   Post subject: Re: "Elsif" All of them can be true, how do you diffrentiate?

Sweet! I got it, thanks for the help both of you guys.
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: