Thursday 11 January 2024

Switch Case

let score = 85

switch score {

case 0..<60:

    print("You failed.")

case 60..<70:

    print("You passed, but it could be better.")

case 70..<80:

    print("You did well.")

case 80..<90:

    print("You did very well.")

case 90...100:

    print("Congratulations! You aced it.")

default:

    print("Invalid score.")

}

Example 2


var aNumber = Int(readLine()!)!

func dayOfTheWeek(day: Int) {
    // Use the provided parameter 'day' in the switch statement
    switch day {
    case 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: Invalid day")
    }
}

// Call the function with the provided variable 'aNumber'
dayOfTheWeek(day: aNumber)

No comments:

Post a Comment

Mức thuế ở Úc từ 07/2024

Chính phủ Úc đã thay đổi các mức thuế suất cho thu nhập cá nhân và các mức thu nhập (được gọi là ‘ngưỡng’) áp dụng những thuế suất này. Việc...