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

Username:   Password: 
 RegisterRegister   
 How to find the range of integers
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
mimimi




PostPosted: Sat Oct 10, 2015 9:17 am   Post subject: How to find the range of integers

What is it you are trying to achieve?

I am trying to write a program that can take any series of positive integers and output the range from smallest to largest.

What is the problem you are having?

How can I find the range when I do not know how many integers the user will enter?

Please specify what version of Turing you are using

4.1.1
Sponsor
Sponsor
Sponsor
sponsor
DemonWasp




PostPosted: Sat Oct 10, 2015 12:26 pm   Post subject: RE:How to find the range of integers

You don't need to store all of the integers. You just need to remember the largest and the smallest you have seen so far.
mimimi




PostPosted: Sat Oct 10, 2015 10:08 pm   Post subject: Re: How to find the range of integers

This is what I have so far. Is there a way that I can declare minint as something other than the largest value that Turing will allow the user to input (10000000)?

var minint, maxint, integer : int
maxint := 0
minint := 10000000

loop
put "Enter an integer."
get integer
if integer < 0 then
exit
elsif integer > maxint then
maxint := integer
elsif integer < minint then
minint := integer
end if
end loop

put "The range of the previous integers is ", maxint - minint, "."
DemonWasp




PostPosted: Sun Oct 11, 2015 12:46 am   Post subject: RE:How to find the range of integers

There are a few options. You could set the initial value to the maximum value you can store in an integer: http://compsci.ca/holtsoft/doc/maxint.html . You could also notice that your problem only requires you to handle positive integers -- so what could you do to store a value that means "not yet assigned" to your maxint value?
mimimi




PostPosted: Sun Oct 11, 2015 6:04 pm   Post subject: Re: How to find the range of integers

Okay I set the initial value to maxint, thank you so much! Smile
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: