Saturday 31 October 2020

A Swift Program on switch case

 In this program we are checking the student grades using switch case


//Creating and storing a variable

    var percentage:Float = 100

    //Creating a function to calculate student grades

    func grades()

    {

        switch percentage //switch case to check grades

        {

            case 70...100:

                print("Congratulations you got distinction")

            case 60..<70:

                print("Congratulations you got First Class")

            case 50..<60:

                print("Congratulations you got Second Class")

            case 40..<50:

                print("Congratulations you got Compartmental Class")

            default:

                print("Failed in exam")

            

        }


    }

No comments:

Post a Comment