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

Username:   Password: 
 RegisterRegister   
 how to get the biggest number and smallest number
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
DAV1209




PostPosted: 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
Sponsor
sponsor
Blade




PostPosted: 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




PostPosted: 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.
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
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  [ 3 Posts ]
Jump to:   


Style:  
Search: