Ad
Code
Diff
  • func gradeCalc(_ score: Int) -> String {
        do {
            return try letterGrade(for: score)
        } catch {
            return "Not a grade"
        }
    }
    
    func letterGrade(for score: Int) throws -> String {
        switch score {
        case 90...100:
            return "A"
        case 80..<90:
            return "B"
        case 70..<80:
            return "C"
        case 60..<70:
            return "D"
        case 0..<60:
            return "F"
        default:
            throw ParameterError.outsideOfValidRange
        }
    }
    
    enum ParameterError: Error {
        case outsideOfValidRange
    }
    
    • func gradeCalc(_ score: Int) -> String {
    • if (score < 0 || score > 100)
    • {
    • return "Not a grade";
    • }
    • return ["F","F","F","F","F","F","D","C","B","A","A"][score / 10];
    • }
    • do {
    • return try letterGrade(for: score)
    • } catch {
    • return "Not a grade"
    • }
    • }
    • func letterGrade(for score: Int) throws -> String {
    • switch score {
    • case 90...100:
    • return "A"
    • case 80..<90:
    • return "B"
    • case 70..<80:
    • return "C"
    • case 60..<70:
    • return "D"
    • case 0..<60:
    • return "F"
    • default:
    • throw ParameterError.outsideOfValidRange
    • }
    • }
    • enum ParameterError: Error {
    • case outsideOfValidRange
    • }