Converting array to Double and work with its content

I'm kinda new to Swift, and I'm trying to create a command-line program: at first, it should get 3 (exactly 3, not more or less, and divided by spaces) numbers from user via standard input and apply them in trigonometric calculations later. As far as I understand, I should use readLine() function to get the user input in terminal, and also put those values into array to not repeat myself and write same code for every value.

But this is the point where difficulties begin: even though I could've convert single readLine() value (which is String optional) to Double, in my situation I need to get an array, convert all of the values and also check if user input is correct. In case the user has entered incorrect value or values (random symbols or words instead of numbers, for example) I need to display an error message and return him to start of the program, i.e. ask user to enter the numbers again. How do I do that?

#arrays #swift

5 Likes1.35 GEEK