What is wrong in this
First, the formatting… 😉
var aNumber = Int(readLine()!)!
func dayOfTheWeek(day: Int) {
switch dayOfTheWeek {
case 2:
print("Monday")
case 3:
print("Tuesday")
case 4:
print("Wednesday")
case 5:
print("Thursday")
case 6:
print("Friday")
case 7:
print("Saturday")
case 8:
print("Sunday")
default:
print("Error")
}
}
dayOfTheWeek(day: <#Int#>)
This code is not very robust. Unwrapping without checking for nil may cause crashes.
For instance, you'd better write:
var aNumber = Int(readLine() ?? "0") ?? 0
You cannot use the func name in the switch, in addition it would be a wrongType (a func () -> Void, and not an Int for the switch)
Does your week really starts at 2 ? It is probably 0 (maybe 1) ; in anglo saxon world, first day is sunday (0)
So, at the end your code should look like this:
var aNumber = Int(readLine() ?? "0") ?? 10
func dayOfTheWeek(day: Int) {
switch day {
case 1: // if first day is 1 ;
print("Monday")
case 2:
print("Tuesday")
case 3:
print("Wednesday")
case 4:
print("Thursday")
case 5:
print("Friday")
case 6:
print("Saturday")
case 7:
print("Sunday")
default:
print("Error")
}
}
print(dayOfTheWeek(day: aNumber))