- #1
RoboNerd
- 410
- 11
Hi everyone.
I am working on a blackjack game using swift, and I have need to get the user's input from a console. While my code (which is attached below) works in theory, my program does not wait for the user to type some input in the console. Instead, it quickly passes over it and returns an empty string.
If anyone could provide some input that would be great.
My code is shown below:
"""
""""
My console output is as following:
"
Curent hand value is: 10. Do you want another card? (yes/no):
Checkpoint 1
Checkpoint 2
"
-----
My program calls the input() function after it asks the user "Do you want another card?" and as one can see by the printing of the checkpoint lines, the console does not stop and wait.
Could anyone please provide some input as to what is going on?
Thanks in advance.
I am working on a blackjack game using swift, and I have need to get the user's input from a console. While my code (which is attached below) works in theory, my program does not wait for the user to type some input in the console. Instead, it quickly passes over it and returns an empty string.
If anyone could provide some input that would be great.
My code is shown below:
"""
Code:
func input() -> String
{
print("Checkpoint 1")
let input = readLine(stripNewline: true)
print("Checkpoint 2")
if (input != nil)
{
return input!
}
else
{
return ""
}
}
""""
My console output is as following:
"
Curent hand value is: 10. Do you want another card? (yes/no):
Checkpoint 1
Checkpoint 2
"
-----
My program calls the input() function after it asks the user "Do you want another card?" and as one can see by the printing of the checkpoint lines, the console does not stop and wait.
Could anyone please provide some input as to what is going on?
Thanks in advance.
Last edited by a moderator: