Created
May 15, 2015 17:41
-
-
Save mrampton/171989387f5503f06602 to your computer and use it in GitHub Desktop.
Asks for your hw and exam scores, calculates your 3203 grade
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
if __FILE__ == $PROGRAM_NAME | |
hw_weights = [ 40.0, 50.0, 40.0, 36.0, 37.0, 38.0 ] | |
hw_scores = [] | |
hw_scores = hw_weights.each_with_index.collect do |max, i| | |
print "Enter hw #{i+1} score: " | |
(gets.to_f / max) * 20 | |
end | |
lowest_hw = hw_scores.min | |
lowest_index = hw_scores.find_index(lowest_hw) | |
puts "Dropping lowest hw: hw_#{lowest_index + 1} worth #{lowest_hw}/20" | |
hw_scores.delete_at(lowest_index) | |
hw_weights.delete_at(lowest_index) | |
exam_weights = [100, 100, 200] | |
exams = %w(midterm1 midterm2 final) | |
# exam_scores will store percentages | |
exam_scores = exam_weights.each_with_index.collect do |weight, i| | |
print "Enter #{exams[i]} score: " | |
(gets.to_f / weight) | |
end | |
best_score = exam_scores.max | |
worst_score = exam_scores.min | |
best_exam = exam_scores.find_index(best_score) | |
worst_exam = exam_scores.find_index(worst_score) | |
puts "Adjusting your best exam: #{exams[best_exam]} " | |
puts "Adjusting your worst exam: #{exams[worst_exam]} " | |
exam_weights[best_exam] = exam_weights[best_exam] == 100 ? 120 : 220 | |
exam_weights[worst_exam] = exam_weights[worst_exam] == 100 ? 80 : 180 | |
adjusted_exams = exam_weights.each_with_index.collect do |weight, i| | |
exam_scores[i] * weight | |
end | |
hw_grade = hw_scores.inject(:+) | |
exam_grade = adjusted_exams.inject(:+) | |
class_total = (hw_grade + exam_grade) / 5 | |
puts "Class total: #{class_total}" | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment