Re: CASE (added some more info) (fixed a few typos in the pseudo code)
Michael Calkins (Login MCalkins) Moderator Posted May 12, 2012 6:09 PM
Are you wanting the user to type the name of the state to delete?
In that case, loop through the states() array until you find the match.
Here's how you might do it:
have an outer DO loop to prompt (and reprompt) the user for the state to delete.
if the user entered a blank string, exit the loop
have an inner FOR loop to loop through the states() array looking for a case insensitive match.
when you find a match, clear that element of the array, then exit both loops.
print a message that no match was found.
alternatively, you might exit just the inner FOR loop, instead of exiting both loops, if you want to give the user the chance to delete another state. However, then you would need an IF statement for the error message, instead of just printing it unconditionally. In such a case, it is not necessary to introduce another variable to track whether a match was found or not. You can tell from the FOR's counter alone. If the FOR loop is 1 to 50, the counter will be 51 after finishing the loop without a match, but would be less than 51 if the EXIT FOR were executed...
Are you wanting the user to type the array index? (This is how my other modification worked, but might not be ideal.) Then check that the index is within bounds, then delete it.
I think you are going for the first method, but the code looks like you are trying to mix the two methods.
A better method would be to have the user be able to select which one to delete from the display. That is, scroll through the list and let the user select which. However, that is more complicated to code.