Computer Science Canada How to find the range of integers |
Author: | mimimi [ 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 |
Author: | DemonWasp [ 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. |
Author: | mimimi [ 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, "." |
Author: | DemonWasp [ 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? |
Author: | mimimi [ 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! ![]() |