You can additionally make the input string upper or lower case so you only have to worry about character 'A', 'S', and 'W' or 'a', 's', and 'w' but not combination thereof.
Also for tighter code, you could create a function that displays prompt, parses to double (including any error handling if doesn't parse), calculates time based on distance entered and speed of medium and returns. That way any logic changes would only need to be done in one place.
Main Topics
Browse All Topics





by: humanonomicsPosted on 2009-06-22 at 09:28:32ID: 24684030
Why not try the following ?
Select allOpen in new window