Computer Science Canada

How do I find the 3 highest values within an array?

Author:  t2xplosions [ Sun Dec 11, 2016 2:42 am ]
Post subject:  How do I find the 3 highest values within an array?

What is it you are trying to achieve?
Create a program that will take in rainfall amounts and then create a report for them.


What is the problem you are having?
I need to put a notice beside the months that have the top 3 rainfalls. I don't know how to find the top 3 within an array.

Post any relevant code (You may choose to attach the file instead of posting the code if it is too long)
This is all I've got so far. I stopped where I have to put the notice for the top 3 months.
There's also the error message of "Assigned value is the wrong type" at
average:=(average+rain(count))/count

Turing:


    var months : array 1..12 of string
    var rain : array 1..12 of int
    var average : int :=0
    var total : int :=0
   
        months(1):="Jan"
        months(2):="Feb"
        months(3):="Mar"
        months(4):="Apr"
        months(5):="May"
        months(6):="Jun"
        months(7):="Jul"
        months(8):="Aug"
        months(9):="Sep"
        months(10):="Oct"
        months(11):="Nov"
        months(12):="Dec"
   
        for count : 1..12
            put "Tell me the total rainfall for the month of ", months(count)
            get rain(count)
            average:=(average+rain(count))/count
            total:=total+rain(count)
        end for
       
        for count : 1..12
            put months(count), ": ", rain(count)
            if rain(count)>=



Please specify what version of Turing you are using
4.1.1

Author:  Insectoid [ Sun Dec 11, 2016 9:23 am ]
Post subject:  RE:How do I find the 3 highest values within an array?

Can you think of a way to find just the top month instead of the top three?

Author:  Presto81 [ Mon Dec 19, 2016 9:24 am ]
Post subject:  RE:How do I find the 3 highest values within an array?

I suspect something's wrong with how you're using 'count' in here. Because it's saying it's the wrong type, I'd take a look at where you learned that piece containing 'count' and see if something doesn't match up.


: