Computer Science Canada Programming C, C++, Java, PHP, Ruby, Turing, VB   Username:   Password: Wiki   Blog   Search   Turing   Chat Room  Members
How do I find the 3 highest values within an array?
Author Message
t2xplosions

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

Insectoid

Posted: 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?
Presto81

Posted: 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.
 Display posts from previous: All Posts1 Day7 Days2 Weeks1 Month3 Months6 Months1 Year Oldest FirstNewest First

Page 1 of 1  [ 3 Posts ]
 Jump to:  Select a forum  CompSci.ca ------------ - Network News - General Discussion     General Forums   -----------------   - Hello World   - Featured Poll   - Contests     Contest Forums   -----------------   - DWITE   - [FP] Contest 2006/2008   - [FP] 2005/2006 Archive   - [FP] 2004/2005 Archive   - Off Topic     Lounges   ---------   - User Lounge   - VIP Lounge     Programming -------------- - General Programming     General Programming Forums   --------------------------------   - Functional Programming   - Logical Programming   - C     C   --   - C Help   - C Tutorials   - C Submissions   - C++     C++   ----   - C++ Help   - C++ Tutorials   - C++ Submissions   - Java     Java   -----   - Java Help   - Java Tutorials   - Java Submissions   - Ruby     Ruby   -----   - Ruby Help   - Ruby Tutorials   - Ruby Submissions   - Turing     Turing   --------   - Turing Help   - Turing Tutorials   - Turing Submissions   - PHP     PHP   ----   - PHP Help   - PHP Tutorials   - PHP Submissions   - Python     Python   --------   - Python Help   - Python Tutorials   - Python Submissions   - Visual Basic and Other Basics     VB   ---   - Visual Basic Help   - Visual Basic Tutorials   - Visual Basic Submissions     Education ----------- - Student Life   Graphics and Design ----------------------- - Web Design     Web Design Forums   ---------------------   - (X)HTML Help   - (X)HTML Tutorials   - Flash MX Help   - Flash MX Tutorials   - Graphics     Graphics Forums   ------------------   - Photoshop Tutorials   - The Showroom   - 2D Graphics   - 3D Graphics     Teams ------ - dTeam Public

 Style: Appalachia blueSilver eMJay subAppalachia subBlue subCanvas subEmjay subGrey subSilver subVereor Search: