+ 1

Code Coach input in Swift

Hi, new to coding in Swift The Code Coach assigns a problem that asks you to do something with an input. I create the code and make the first line a variable assigning the first input value. When I run the code, it works for the first test. But it will fail the second test because it wants a new input to be used, which will change the expected output. I can change my variable value to the input for test 2, but it will then fail test one??? How do I get past this point? Thanks for the help!

16th Oct 2022, 6:26 PM
Peter Lowery
3 Answers
+ 2
Oh sorry. I didn't mean to use the exact phrasing I wrote, but to use whatever form of input the language uses. looks like it should be something like "let a = readLine()" without the ". Can you copy the code coach, create a new code in the code playground and paste it there, then save it and add it here?
16th Oct 2022, 8:20 PM
Ausgrindtube
Ausgrindtube - avatar
+ 1
Your variable should be the input, not the value of the input. Example: a + b int a = input int b = input This way, any input give their result as opposed to one "hard coded" result.
16th Oct 2022, 7:19 PM
Ausgrindtube
Ausgrindtube - avatar
0
Thanks Ausgrindtube I have tried the following: Int a = input Int a = Input int a = input int a = Input All of the above with spaces around the = removed, All of the first four but with == And then started trying brackets, colons. All combinations returned errors. I cant figure out the Swift syntax to use the input. While searching, I came across readLine(). Ive tried that but it appears to set as a string and not a variable or integer.
16th Oct 2022, 7:45 PM
Peter Lowery