lundi 14 mai 2018

How do I create a method for rounding grades? I feel like I have it mostly complete

I want to be able to take an array of numbers and run them through my method. The method should do the following: 1) Round up to the nearest multiple of 5, if the remainder of 5 is 3 or 4. (Ex. 68 would round up to 70, but 67 would remain 67)

2) Anything below a 58 is a failing grade, so a 57 or lower will just return the grade.

Below is the following code that I have, but it is not working properly.

def gradingStudents(grades)
    grades.each do |x|
        remainder = grade % 5
        if(grade < 58)
            return grade
        elsif (rem > 3)
            answer = grade - rem + 5
            return answer
        else 
            return grade
        end
    end
end

Where am I messing up at? Thanks!

Aucun commentaire:

Enregistrer un commentaire