What ugly code!

by Solitaire (Login Solitaire1)
S

Forgive me for being blunt, but all those GOTOs are enough to make me puke. I just don't have the stomach for it.

Please get rid of those GOTOs and learn to use a proper loop. I won't even look at that code until you clean it up.


Here is an example of a FOR-NEXT loop to get you started. This will get the average of 5 numbers the user enters, but it doesn't get the maximum or minimum values. I'll let you try to figure that out for yourself. There are several ways of doing it. Give it a try and post your code WITHOUT ANY GOTOS!!!

FOR x = 1 to 5
   INPUT "Enter a number:  ", snum$
   num = VAL(snum$)
   total = total + num
NEXT x
average = total / 5
PRINT average



    
This message has been edited by Solitaire1 on Feb 25, 2011 7:03 PM
This message has been edited by Solitaire1 on Feb 25, 2011 7:00 PM

Posted on Feb 25, 2011, 6:47 PM

Respond to this message   

Return to Index


Response TitleAuthor and Date
LOL... on Feb 25
wellHC on Feb 26
 AND ALSOhc on Feb 26
  ...HC on Feb 26
 You need to get a base value for max and min.Solitaire on Feb 26
  * The less than symbol < won't display in posts :-P on Feb 26
  whoaHC on Feb 26
   * DIM defines the variable type on Feb 27
   Variables must be defined by type in most languages.Solitaire on Feb 27
    Thanks!HC on Feb 27