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

Username:   Password: 
 RegisterRegister   
 Easy Turing problem that I'm stuck on =[
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
rubdoo




PostPosted: Thu Feb 26, 2009 7:59 pm   Post subject: Easy Turing problem that I'm stuck on =[

Hey, I'm really a noob at Turing. We just started and I'm stuck on this problem.

Basically, I just have to have the user input a bunch of numbers, then output the range (lowest number to highest number inputted).
I hope that made sense...

Anyways, this is what I have so far:

code:

var num, high, low : int
high := 0
low := 0

put "Type '-1' to finish"
put "------------------------------------------------------"
put "Enter positive numbers:"
put ""

loop
    get num
    exit when num = -1
    if num > high then
        high := num
    elsif num < high then
        low := num
    end if
end loop

put ""
put "------------------------------------------------------"
put "Those numbers range from: ", low, " - ", high


If anyone can help, it would be highly appreciated. Wink
Thanks.
Sponsor
Sponsor
Sponsor
sponsor
andrew.




PostPosted: Thu Feb 26, 2009 8:03 pm   Post subject: RE:Easy Turing problem that I\'m stuck on =[

It outputs the range, but do mean to output all the numbers? Like if I enter 3, 7, and 6, it should say 3, 5, 7? If you want to do that, you have to sort the numbers. Check out this Wikipedia article. It may help you. Basically what you're doing is you're looking at each number at a time and then deciding whether it's lower than the previous. If it is then it goes before the previous, if not then it stays where it is.
rubdoo




PostPosted: Thu Feb 26, 2009 8:07 pm   Post subject: RE:Easy Turing problem that I\'m stuck on =[

No. If you enter that, it should output: 3-6
Tony




PostPosted: Thu Feb 26, 2009 8:13 pm   Post subject: RE:Easy Turing problem that I\'m stuck on =[

can you at least say what the problem is? like "it doesn't output the proper low bound".

Then I would ask you to explain how you would figure out if a number is the lowest in a set.
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
rubdoo




PostPosted: Thu Feb 26, 2009 8:17 pm   Post subject: RE:Easy Turing problem that I\'m stuck on =[

Oh, yeah. I guess I forgot that Razz
And yeah, that is the problem.

And i know how to do that in real life, but like... not in Turing. hah....
Tony




PostPosted: Thu Feb 26, 2009 8:18 pm   Post subject: RE:Easy Turing problem that I\'m stuck on =[

well how would you do that on paper?
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
andrew.




PostPosted: Thu Feb 26, 2009 8:22 pm   Post subject: RE:Easy Turing problem that I\'m stuck on =[

I still don't understand the problem. Is it supposed to just output the first and last number that you enter?
rubdoo




PostPosted: Thu Feb 26, 2009 8:23 pm   Post subject: RE:Easy Turing problem that I\'m stuck on =[

I'd look at the numbers, and compare the 2nd one with the 1st and find the smaller one, then compare the 3rd one with the smaller one of the 1st and 2nd ones, and go on down the list to the end. Then I'd have the smallest one...
Sponsor
Sponsor
Sponsor
sponsor
rubdoo




PostPosted: Thu Feb 26, 2009 8:24 pm   Post subject: RE:Easy Turing problem that I\'m stuck on =[

andrew, it's supposed to find the smallest number in the list, and then the biggest, and output them.
Tony




PostPosted: Thu Feb 26, 2009 8:29 pm   Post subject: RE:Easy Turing problem that I\'m stuck on =[

you've got the steps down correctly, now you just need to say the same thing in code. You're already looping over the numbers, and you know how to compare them.

All you need to do is compare the same pair of numbers as you've described above.
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
saltpro15




PostPosted: Thu Feb 26, 2009 8:35 pm   Post subject: RE:Easy Turing problem that I\'m stuck on =[

+1 karma to Tony for knowing the answer to everything, as usual Very Happy keep up the good work on the blog too
rubdoo




PostPosted: Fri Feb 27, 2009 12:12 pm   Post subject: RE:Easy Turing problem that I\'m stuck on =[

I think I got it. lol.

This works:

code:

var num, high, low : int
high := 0
low := maxint

put "Type '-1' to finish"
put "------------------------------------------------------"
put "Enter positive numbers:"
put ""

loop
    get num
    exit when num = -1
    if num > high then
        high := num
    end if
    if num < low then
        low := num
    end if
end loop

put ""
put "------------------------------------------------------"
put "Those numbers range from: ", low, " - ", high
Tony




PostPosted: Sat Feb 28, 2009 12:24 am   Post subject: RE:Easy Turing problem that I\'m stuck on =[

looks good. The only exception is if I was to enter in an empty list (that is, first entry is -1).
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
rubdoo




PostPosted: Sat Feb 28, 2009 7:16 am   Post subject: RE:Easy Turing problem that I\'m stuck on =[

Yeah... but anyways, thanks Razz
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  [ 14 Posts ]
Jump to:   


Style:  
Search: