Skip to content

Instantly share code, notes, and snippets.

@jamesmichiemo
Last active December 18, 2015 10:09
Show Gist options
  • Select an option

  • Save jamesmichiemo/5766151 to your computer and use it in GitHub Desktop.

Select an option

Save jamesmichiemo/5766151 to your computer and use it in GitHub Desktop.
expression in Ruby language
# Exam
# Problem: Matt is a teacher grading the last exam taken for his course and he needs to log the progress of his students in his roll boo.
# There are 16 students in his class. If 10 of those students passed the exam, what percent failed the class
# Calculate the percent of failures in Matt's class.
#
print "Matt is a teacher grading the last exam taken for his course and he needs to log the progress of his students in his roll book. There are 16 students in his class. If any of these students fail the exam, they will fail the class. Only 10 of Matt's students passed the exam. Calculate the percentage of failures.\n\nEnter the total amount of students in Matt's class. "
studentTotal = gets.chomp().to_f # <= 16 students
print "Enter how many students passed Matt's class. "
studentsPassing = gets.chomp().to_f # <= 10 students
studentsFailing = studentTotal - studentsPassing; # => 6
failRate = (studentsFailing / studentTotal) * 100; # => 37.5
puts "#{failRate}% of the class failed Matt's exam."
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment