Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

help with q basic

Status
Not open for further replies.

Dimebagromero

Programmer
Oct 4, 2012
1
US
I have a string of code. I need to be able to enter a series of numbers, in no particular order, and then display the highest and lowest number. After a -99 is entered I need it to end the WHILE loop. What I have makes it loop, but when I enter the -99 it does not end the loop and display the bottom half of the code

CLS
' Declaration
numberEntered = 0
largestNumber = 0
smallestNumber = 999999

' Input the Weight of the Package
PRINT "Largest and Smallest"
PRINT
PRINT "Enter a series of numbers and displays the highest and lowest number."
PRINT "The numbers do not have to be entered in any special order."
PRINT "The number must be less than 1 million."
PRINT "Enter -99 to end the program."
PRINT
INPUT "Enter your first number "; numberEntered

'Execute the while loop until a -99 is entered as the number
DO
WHILE numberEntered <> -99
IF numberEntered > largestNumber THEN
largestNumber = numberEntered
IF numberEntered < smallestNumber THEN
smallestNumber = numberEntered
END IF
END IF
INPUT "Enter your next number "; numberEnterd
WEND
LOOP


'Display the largest and smallest numbers
PRINT
PRINT "You entered a series of numbers."
PRINT "The largest number is ; largestNumber"
PRINT "The smallest number is ; smallestNumber
 
It does exit, but into the first loop. You have two loops; a DO..LOOP surrounding a WHILE..WEND. Take out the WHILE..WEND and replace it with a DO..LOOP UNTIL and you should be set. Also, the IF..THEN logic is not blocked properly. If the IF..THENs are not meant to be nested, make sure you end an IF..THEN statement before another one starts.

Code:
DO 
   INPUT "Enter your next number "; numberEntered
   IF numberEntered > largestNumber THEN
      largestNumber = numberEntered
   END IF
   IF numberEntered < smallestNumber THEN
      smallestNumber = numberEntered
   END IF
LOOP [red]UNTIL (numberEntered = -99)[/red]

-Geates




"I do not offer answers, only considerations."
- Geates's Disclaimer

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top