Posted: Sun Dec 04, 2011 6:19 pm Post subject: Turing and Conditions. Please help me.
What is it you are trying to achieve?
I really need help with this condition question in a turing e-book
What is the problem you are having?
This is the question:
Write a program to output a backwards count by 5s from 100 down to 5. Modify it so that you count from 100 down to 50. Modify it so that before you start the count you can input a number between 100 and 50 so that the program will stop when the count would be less than the number input. For example the execution might be like this:
What number do I stop at? 82
Stop when count less than 82
100
95
90
85
Describe what you have tried to solve this problem
I tried it a couple times without like. I got the part where you had to count down to 5 and to 50, but I don`t get the last part of the question. Like how to get the user to input the number they would like for it to count down to. Please help me. I think that it has something to do with the mod function.
Post any relevant code (You may choose to attach the file instead of posting the code if it is too long)
<Answer Here>
Turing:
<var modifiednumber: int:=100 var stophere: int loop put"Enter the number you would like to count down to, it has to be in between 50 and 100" get stophere
put"Stop when count less than ", stophere
exitwhen modifiednumber < stophere
modifiednumber:= modifiednumber-5 put modifiednumber
endloop
>
Please specify what version of Turing you are using
4.1
Sponsor Sponsor
Tony
Posted: Sun Dec 04, 2011 6:32 pm Post subject: RE:Turing and Conditions. Please help me.
code:
put "Enter the number you would like to count down to, it has to be in between 50 and 100"
How many times do you want to ask this? If it's just once, why is it inside of a loop (do something many times).
Posted: Sun Dec 04, 2011 7:17 pm Post subject: Re: Turing and Conditions. Please help me.
You should use a decreasing for statement:
code:
for decreasing y : 100 .. stophere by 5
put y
end for
huskiesgoaler34
Posted: Sun Dec 04, 2011 7:34 pm Post subject: Re: Turing and Conditions. Please help me.
The for statement is just a type of loop that is ran a specific amount of times (therefore calling it a counted loop). This will allow you to run the loop until you reach stophere, your number input.
varman
Posted: Sun Dec 04, 2011 7:52 pm Post subject: RE:Turing and Conditions. Please help me.
@Tony
It is because the numbers need to be shown decreasing.
huskiesgoaler34
Posted: Sun Dec 04, 2011 7:58 pm Post subject: Re: RE:Turing and Conditions. Please help me.
varman @ Sun Dec 04, 2011 7:52 pm wrote:
@Tony
It is because the numbers need to be shown decreasing.
I know that the question is directed at Tony but I felt that I could clear it up faster because I'm already online.
Where the OP placed his put/get statement has no effect on the numbers being shown in a decreasing fashion. It would have no impact on how he would get the numbers to decrease by 5 to the value of stophere.
PS, I see that you are new to the board (only 2 posts). Welcome!
Tony
Posted: Sun Dec 04, 2011 8:05 pm Post subject: RE:Turing and Conditions. Please help me.
Posted: Sun Dec 04, 2011 8:17 pm Post subject: Re: RE:Turing and Conditions. Please help me.
My response was geared towards answering
varman wrote:
@Tony
It is because the numbers need to be shown decreasing.
Varman asked if the OP's code had to do with the numbers being shown decreasing and I simply said no.
I don't see how Varman's question relates to your original response at all.
Sponsor Sponsor
Tony
Posted: Sun Dec 04, 2011 8:22 pm Post subject: RE:Turing and Conditions. Please help me.
varman @ Sun Dec 04, 2011 6:19 pm wrote:
loop
put "Enter the number you would like to count down to, it has to be in between 50 and 100"
...