Q:

Write a Ruby program to retrieve the total marks where subject name and marks of a student stored in a hash

0

Write a Ruby program to retrieve the total marks where subject name and marks of a student stored in a hash.

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

student_marks = Hash.new 0
student_marks['Literature'] = 74
student_marks['Science'] = 89
student_marks['Math'] = 91
total_marks = 0
student_marks.each {|key,value|
              total_marks +=value
        } 
puts "Total Marks: "+total_marks.to_s

Output:

Total Marks: 254

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Similar questions


need a help?


find thousands of online teachers now