• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1387
  • Last Modified:

Psuedocode: How do I Display the largest list of Positive Numbers?

I am so stuck with this problem im new to this and very very confused.
Heres the Question      Find and Display the largest of a list of Postive Numbers entered by the user. The user should indicate that he/she has finished entering numbers by entering 0. How would i solve this problem?
0
Jasminne
Asked:
Jasminne
  • 2
  • 2
  • 2
  • +5
3 Solutions
 
Frosty555Commented:
There's a big difference between the "largest list of positive numbers" and the "largest OF a list of positive numbers". Which is it?
0
 
JasminneAuthor Commented:
Largest of a list....?
0
 
ozoCommented:
start with the largest so far being less than any positive number.

read each number in turn and if it is larger than the largest so far, adjust the largest so far to be equal to the new number
as long as the number is not 0, go back and read another number
0
Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
JasminneAuthor Commented:
I dont know if this is right is there any way to shorten this solution
Declare Number, Highest as Float
      Write Highest Number
      Write This program will find the highest number in a list of positive numbers entered by the 
      Write user.
      Write Please enter a positive number, enter 0 when you are finished: 
      Input Number
      While Number < 0
            Write You have entered a negative number.  Please enter a positive number, enter 
            Write 0 when you are finished: 
            Input Number
      End While
      Set Highest = Number
      While Number != 0
            Write Please enter another positive number, enter 0 when you are finished: 
            Input Number
            While Number < 0
                  Write You have entered a negative number.  Please enter a positive number, 
                  Write enter 0 when you are finished: 
                  Input Number
            End While
            If Number > Highest
                  Set Highest = Number
            End If
      End While
      Write The highest number that you entered is: , Highest
End Program
0
 
ozoCommented:
> is there any way to shorten this solution
given the similarities  between the code for reading the first number and reading subsequent numbers, you may be able to collect it into a subroutine that you only need to write once,
Or, you may be able to arrange your initial conditions such that only the code for reading the rest of the list is needed because you have arranged fir it to do the right thing when it reads hr first number.

Why is  shortening the solution important?
0
 
Frosty555Commented:
Shortening the solution is important when, academically, your teacher considers a "shorter" solution a "better" solution ;)

Simple pseudocode:

Begin Program
   LastMaxValue = 0
   Begin Loop
       Read In Number
       If Number > LastMaxValue
           LastMaxValue = Number
       End If
       If Number = 0
           Break out of loop
       End If
       If Number < 0
            Fail with an error / throw exception
       End If
   End Loop

   Show LastMaxValue to User
End Program

The aesthetic aspects of the program are unrelated, and up to you to implement. You can make it as fancy or as simple as you like in that respect.
0
 
thehagmanCommented:
As to shortness: I don't see in the specification of the problem that the program should be fail-safe enough to rejedt negative numbers. Hence that test might be thrown away (though input validation *is* a valid issue)
0
 
jakiejCommented:
The following would simply "Find and Display the largest of a list of Postive Numbers entered by the user", without doing anything fancy.

Set L = 0
Do
  Input Number
  If Number>L
    Set L = Number
  End If
Until Number =0
If L > 0
  Write "The Largest is", L
Else
  Write "No positive number has been entered before entering 0."
End If
0
 
foliage_Commented:
step 1: logic to get the integers, once a 0 character is entered move on to step 2
step 2: get all the integers from the use storedt in an arraylist
step 3: sort the array list from largest to smallest
step 4: print the list out.

To shorten the solution, use the highest level language you can find, technically it should still pass as pseudo code still.

Use java or C# and you should be able to get it down to maybe 15 lines, a few print statements, a few try clauses and a call to sort.
0
 
darkyin87Commented:
To find the largest and smallest number in an array, take the first value of array as largest and smallest number initially, and test against all the values of array to find the appropriate values.

Declare Number[100] As Integer
Declare X, Largest, Smallest, Count As Integer
Set Count = 0

Write "Enter a number:"
Input X

While Number != 0
Set Number[Count] = X

// Take the first value of array as smallest and largest initially
IF Count equals 0 Then
Set Largest = Number[Count]
Set Smallest = Number[Count]
End IF

// Find the largest value in the array
IF Largest < Number[Count] Then
Set Largest = Number[Count]
End IF

// Find the smallest value in the array
IF Smallest > Number[Count] Then
Set Smallest = Number[Count]
End IF

Set Count = Count + 1
Write "Enter a number:"
Input X
End While

For (K = Count - 1; K >= 0; K++)
Write Number[K]
End For
0
 
mlmccCommented:
This question has been classified as abandoned and is closed as part of the Cleanup Program. See the recommendation for more details.
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

  • 2
  • 2
  • 2
  • +5
Tackle projects and never again get stuck behind a technical roadblock.
Join Now