Author |
Message |
mimimi
|
Posted: 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 |
|
|
|
|
![](images/spacer.gif) |
Sponsor Sponsor
![Sponsor Sponsor](templates/subSilver/images/ranks/stars_rank5.gif)
|
|
![](images/spacer.gif) |
DemonWasp
|
Posted: 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. |
|
|
|
|
![](images/spacer.gif) |
mimimi
|
Posted: 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, "." |
|
|
|
|
![](images/spacer.gif) |
DemonWasp
|
Posted: 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? |
|
|
|
|
![](images/spacer.gif) |
mimimi
|
Posted: 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 Smile](http://compsci.ca/v3/images/smiles/icon_smile.gif) |
|
|
|
|
![](images/spacer.gif) |
|