Skip to content

Instantly share code, notes, and snippets.

@FaisalFehad
Last active September 8, 2016 15:54
Show Gist options
  • Save FaisalFehad/794beba1d9b778ee9772bbac2e246864 to your computer and use it in GitHub Desktop.
Save FaisalFehad/794beba1d9b778ee9772bbac2e246864 to your computer and use it in GitHub Desktop.
# an empty array to store the grades
grades = []
# variables for the passing grade and the total number of subjects. You can change them from here.
pass_grade = 50
subjects = 7
# loops until reaches the the number of subjects on the subjects variable
while grades.count < subjects
# prints the message
puts "Please enter a grade:"
# takes the input and assign it to grade varible and then adds it to grades array
grade = gets.to_i
grades << grade
end
# prints the saved grades for confirmation.
puts "Your grades are: #{grades}"
# sums all the of the saved grades in grades array into total varible
total = grades.inject(:+)
# prints the total grades from the total varible
puts "Your total grades is #{total}"
# divides the total to the number of subjects to get the average and assign it to sum varible
sum = total / subjects
# compares the sum with the pass_grade and prints the results as message.
if sum >= pass_grade || sum == pass_grade
puts "You failed!"
else
puts "You passed."
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment