# Write an algorithm in pseudocode

Hi (again) :)
I have been asked to:
Write an algorithm in pseudocode that finds and displays the largest of a list of positive numbers entered by the user and the sum of positive numbers.  The user should indicate that s/he has finished entering numbers by entering a zero.

I was wondering if somebody could have a look over what I've done so far as I'm still not sure I'm getting this right....

Here it is:

DISPLAY “Please enter a number.  This can be negative or positive.  To indicate that you have finished entering numbers, please enter a zero.”
GET Number
WHILE Number is not equal to 0
END IF
STORE Number
IF Number is > 0 add to NumList
SET Highest = Number
IF Number > Highest
SET Highest = Number
WHILE Number is not equal to 0
ADD all numbers together from NumList and ADD to TOTAL
DISPLAY “The largest positive number entered is + Hightest as the sum of the positive numbers is” + TOTAL

Thank you in advance
###### Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Commented:
Maybe, but it does ask to check the list for numbers and then add them rather than check as you go along.
You also wrote it has to be positive and then said enter a negative or positive number.

START
noList = empty
highestNo = 0
total = 0
userValue = 0

While(userValue not 0)
WRITE & FETCH   userValue=  'Enter a number, positive only. Enter 0 when finished'
VALIDATE userValue is Possitive
LOOP

LOOP (Count noList) TIMES
total = total + noList.CurrentValue
if(noList.currentValue > highestNo) THEN (highestNo = noList.currentValue)
LOOP

Maybe???

0
Commented:
Hi,

I've some problems with understanding your Code, but try the followin:

VAR SUM = 0
VAR BIGGESTNUMBER = 0

WHILE (NUM = ASK(“Please enter a number.  This can be negative or positive.  To indicate that you have finished entering numbers, please enter a zero.”)
SUM += NUM
IF NUM > BIGGESTNUMBER
BIGGESTNUMBER = NUM
END WHILE

DISPLAY "The largest number is " + NUM
DISPLAY "The sum is " + SUM
0
Author Commented:
Thank you to both of you for your advice :)
50cal - the user is allowed to enter either a negative or positive number but the program is only supposed to account for the positive numbers.
0
Commented:
Think this is a bit better, my prior one wouldn't of worked properly when 0 was entered.

userValue = 1
noList = [null]
totalValue = 0
highestNo = 0

WHILE(1=1) DO
PRINT "Enter a possitive number, Enter 0 to finish"
userValue = GET_NUMBER
IF(userValue = 0) THEN BREAK_LOOP
IF(userValue IsPossitive) THEN noList.ADD(userValue)
LOOP

i = 0

LOOP (COUNT noList) TIMES
totalValue = totalValue + noList.CurrentElementValue(i)
if(noList.CurrentElementValue(i) > highestNo) THEN (highestNo = noList.CurrentElementValue(i))
i + 1
LOOP
0
Commented:
Review of Yours as your questions asks.

DISPLAY “Please enter a number.  This can be negative or positive.  To indicate that you have finished entering numbers, please enter a zero.”   >> Seems Fine
GET Number   >>Seems Fine
WHILE Number is not equal to 0
DISPLAY “Please enter your next number.”   >> You dont appear to be collecting the new number
here - just displaying enter a number.
END IF
STORE Number    >> Not part of the loop - will only do this once?
IF Number is > 0 add to NumList  >> Again - not part of the loop, will only check the final answer.
SET Highest = Number    >> Highest is now the new number entered
IF Number > Highest            >> then your comapring the new number to highest which you just set allready
I.E,
Enter 0
Number = 0
Then you set highest to 0
then you compare number (0) to highest (0)
So it's not really checking.

SET Highest = Number
WHILE Number is not equal to 0  >> Just checking 1 number? Not list?
ADD all numbers together from NumList and ADD to TOTAL
DISPLAY “The largest positive number entered is + Hightest as the sum of the positive numbers is” + TOTAL
0
Commented:
Sorry, I missed the thing with counting only positive numbers...

VAR SUM = 0
VAR BIGGESTNUMBER = 0

WHILE (NUM = ASK(“Please enter a number.  This can be negative or positive.  To indicate that you have finished entering numbers, please enter a zero.”)
IF (NUM < 0) CONTINUE
SUM += NUM
IF NUM > BIGGESTNUMBER
BIGGESTNUMBER = NUM
END WHILE

DISPLAY "The largest number is " + NUM
DISPLAY "The sum is " + SUM
0
Author Commented:
Thank you both very much for you help - it is invaluable to a noob like me :)

schlueter - could you please explain this part as I would of thought it would continue if NUM >0 and not the other way around:

IF (NUM < 0) CONTINUE
SUM += NUM

50cal - thank you for reviewing my work - I am making some changes now :)
0
Commented:
IF NUM < 0 CONTINUE

This means that for a number small than zero nothing will happen (loop continues and asks for the next number)

SUM += NUM

If the number is bigger than zero (loop will end if "num = 0", because it is false OR continue, if smaller than zero), NUM will be added to SUM
0
Author Commented:
schlueter, I'm really sorry if I'm coming across as stupid but I'm totally new to this.  Which part of this code shows that if a zero is entered, it is terminated?
0
Commented:
WHILE (NUM = ASK(“Please enter a number.”));

If the number is 0 (this means: false) , the loop will cancel...
0
Author Commented:
Thank you so much for your help - I think I am starting to get the hang of this a bit now :)
0
Commented:
Okay, I hope your problem was solved.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

###### It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Algorithms

From novice to tech pro — start learning today.