Computer Science Canada "Elsif" All of them can be true, how do you diffrentiate? |
Author: | alex12342011 [ 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)
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. |
Author: | TheGuardian001 [ 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:
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. |
Author: | alex12342011 [ 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 |
Author: | Tony [ 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.
It's important to understand how
evaluates to true for any number. |
Author: | alex12342011 [ 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. |