Psuedocode, finding highest value in an array
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2

Thread: Psuedocode, finding highest value in an array

  1. #1
    Join Date
    Sep 2011
    Posts
    1

    Psuedocode, finding highest value in an array

    Hi, I'm a total novice at computing and have been asked to find the highest value in a 2D array.

    This is what I have to fill in....

    Code:
    ;--------------------------------------------------------------------
    ; Given a 2-D array of sales.  
    ; Print out each individual item with a total of the sales for that
    ; item.
    ; Print out the name of the item with the
    ; highest single monthly sale, the month it sold, and the amount.  
    ;--------------------------------------------------------------------
    
    define MAXPRODUCTS = 5			; Maximum number of products
    string Product[MAXPRODUCTS] = "WKD", "ICE", "Red Bull", "Rentless", "Monster"
    integer Sales[MAXPRODUCTS, 2] = 2000, 1650, 1500, 2050, 1800, 1700, 2200, 2400, 1750, 1550
    
    begin
    	; Print out all items and total for each
    	PrintAll ()					; Call procedure to print all	
    	
    	; Find the item with the highest single monthly sale
    	FindHighest ()				; Call procedure to find best seller
    end
    
    ;--------------------------------------------------------------------
    ; Procedure to print out all the items and the sales
    ;--------------------------------------------------------------------
    procedure PrintAll ()
    
    
    end procedure
    
    
    ;--------------------------------------------------------------------
    ; Procedure to Find Highest selling product
    ;--------------------------------------------------------------------
    procedure FindHighest ()
    
    
    end procedure

    Thanks for any help

  2. #2
    Join Date
    May 2009
    Posts
    2,413

    Re: Psuedocode, finding highest value in an array

    Finding extreme values is standard procedure.

    Introduce a variable called maxValue or something. Assign the first value of the array to maxValue. Then loop through all values in the array once and for each value check whether it's higher than maxValue. If it is, assigned it to maxValue. Afterwards maxValue will hold the highest value of the array.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center