-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathday2.rb
More file actions
135 lines (102 loc) · 3.48 KB
/
day2.rb
File metadata and controls
135 lines (102 loc) · 3.48 KB
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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
#Prompt for a number. If the number is greater than 70, print PASSING; otherwise, print NOT PASSING.
puts "Please enter score."
score = gets.chomp.to_i
if score > 70
print "PASSING"
else print "NOT PASSING"
end
#Prompt for a string. If the string is equal to green, print GO, otherwise, print STOP.
puts "Please enter color."
color = gets.chomp
if color == "green"
print "GO"
else print "STOP"
end
#Prompt for a number. If the number is even, print EVEN, otherwise, print ODD.
puts "Please enter number."
x = gets.chomp.to_i
if x.even?
print "EVEN"
else print "ODD"
end
#Prompt for a number. If the number is evenly divisible by 5, print MULTIPLE OF 5, otherwise, print NOT A MULTIPLE OF 5.
puts "Please enter number."
x = gets.chomp.to_i
if x % 5 == 0
print "MULTIPLE OF 5"
else print "NOT A MULTIPLE OF 5"
end
#Prompt for a number. If the number is less than 10, print ONE DIGIT. If the number is 100 or greater, print THREE DIGITS, otherwise print TWO DIGITS.
puts "Please enter number."
x = gets.chomp.to_i
if x < 10
print "ONE DIGIT"
else if x >= 100
print "THREE DIGITS"
else print "TWO DIGITS"
end
end
#Prompt for a jersey number. If that number is 12, 71, or 80, print That number is retired from the Seattle Seahawks!, otherwise do nothing.
puts "Please enter jersey number."
jersey = gets.chomp.to_i
ret_jerseys = [
12,
71,
80
]
if ret_jerseys.include?(jersey)
puts "That number is retired from the Seattle Seahawks!"
end
#Prompt for a state. If the state is Washington, Oregon, or Idaho, print This state is in the PNW, otherwise print You should move to the PNW; it’s great here!
puts "Please enter your state."
state = gets.chomp
pnw_state = [
"Washington",
"Oregon",
"Idaho"
]
if pnw_state.include?(state)
print "This state is in the PNW."
else print "You should move to the PNW; it's great here!"
end
#Prompt for a one of the following: SHORT, TALL, GRANDE, VENTI. Print out the number of ounces that drink includes (8, 12, 16, 20 respectively).
puts "Please enter your beverage size (short, tall, grande, or venti)."
beverage = gets.chomp
if beverage == "short"
print "That beverage contains 8 ounces."
elsif beverage == "tall"
print "That beverage contains 12 ounces."
elsif beverage == "grande"
print "That beverage contains 16 ounces."
elsif beverage == "venti"
print "That beverage contains 20 ounces."
end
#I feel like there is a more elegant way to do the above... will be looking into it.
#Prompt for rate of pay and hours worked. Calculate gross pay. Provide time-and-a-half for hours worked beyond 40 (e.g., if you get paid $10/hr and work 45 hours in a week, you would gross $475 (40 x 10 + 5 x 15).
puts "Please enter rate of pay"
payrate = gets.chomp.to_f
puts "Please enter hours worked."
hrsworked = gets.chomp.to_f
if hrsworked > 40 then
excesshrs = hrsworked - 40
else
excesshrs = 0
grosspay = hrsworked * payrate + (excesshrs * (1.5*payrate))
print "You earned $#{'%.2f' % grosspay.round(2)}."
end
#Rewrite the solution to the previous problem adding this modification: do not process any employee if their hours worked is greater than 60, instead display the message Please see manager.
puts "Please enter rate of pay"
payrate = gets.chomp.to_f
puts "Please enter hours worked."
hrsworked = gets.chomp.to_f
if hrsworked > 40 then
excesshrs = hrsworked - 40
else
excesshrs = 0
end
grosspay = hrsworked * payrate + (excesshrs * (1.5*payrate))
if excesshrs < 20
print "You earned $#{'%.2f' % grosspay.round(2)}."
else
print "See the manager."
end