how to get the biggest number and smallest number
Author 
Message 
DAV1209

Posted: Fri Oct 03, 2003 3:08 am Post subject: how to get the biggest number and smallest number 


my original program is :
var value, sum, average : real
var howMany : int
sum := 0
put skip, "Enter how many numbers in your list: " ..
get howMany
put "OK  enter all the numbers:"
for i : 1 .. howMany
get value
sum := sum + value
end for
average := sum / howMany
put skip, "The average is ", average : 7 : 1, skip
how can i modify the program so that it also finds the biggest and smallest numbers in the list and output those values after having output the average.
They also ask me try to avoid using sentries to start this process.
(Hint: Try assuming that the first value is the biggest(smallest))
i don't know how to do it..
can someone help me plz 





Sponsor Sponsor



Blade

Posted: Fri Oct 03, 2003 7:35 am Post subject: (No subject) 


you have to set 2 variables... one for the biggest number and one for the smallest... then you run a loop to compare each number thats entered to the highest, then the smallest... if its bigger, you set the number thats compared as the new highest or smallest...
ie:
code:  var high:int:=9999
var low:int:=9999
loop
if (num > high) then
high:=num
elsif (num < low) then
low := num
end if
end loop 






Tony

Posted: Fri Oct 03, 2003 4:38 pm Post subject: (No subject) 


you should put this IF set in the forloop where they enter the value. This way you dont have to store all the values in an array and run the loop again. 
Tony's programming blog. DWITE  a programming contest. 





