-
Notifications
You must be signed in to change notification settings - Fork 0
/
firstapp.rb
76 lines (44 loc) · 1 KB
/
firstapp.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
GRADES = {"a" => 4, "b+" => 3.5, "b" => 3, "c+" => 2.5 , "c" => 2 , "d+" => 1.5, "d" => 1, "f" => 0 }
def gt
return gets.chomp
end
def nextl
return puts ""
end
def lines
return"###############################################################"
end
def inpgr
x=gt
while not GRADES.keys.include? x.downcase
print"Invalid Entry. Try Again : "
x=gt
end
x.downcase!
return GRADES[x]
end
p "################### My GPA Calculator #####################"
nextl
print "Enter no. of subjects: "
num = gt.to_i
nextl
gp=[]
cr=[]
num.times do |i|
puts"##################### Subject #{i+1} ############################"
nextl
print "Enter the grade in this subject: "
gp[i]= inpgr
nextl
print "Enter the credit hours of this subject: "
cr[i]=gt.to_f
nextl
nextl
end
tcr=cr.inject(:+)
n=0
num.times do |i|
n += (gp[i]*cr[i])
end
gpa = n/tcr
p "################## Your GPA is : #{gpa} ######################"