-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathelections_final.rb
More file actions
52 lines (40 loc) · 1.32 KB
/
elections_final.rb
File metadata and controls
52 lines (40 loc) · 1.32 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
puts "Welcome to Election Day!\nVoting is an important civic duty!"
puts "Your candidate choices are: John, Paul, Ringo, and George."
puts "But if you don't see a candidate you like, feel free to write one in!"
puts "Please cast your vote then step aside so the next person gets their turn."
puts "Voting officals: Please enter <end voting> when polls have closed."
candidates = ["john", "paul", "ringo", "george"]
voting = []
counts = []
vote = ""
until vote == "end voting"
print "Enter your vote here: "
vote = gets.chomp.downcase
voting.push(vote)
exists = false
candidates.each do |candidate|
if vote == candidate || vote == "end voting" || vote == ""
exists = true
end
end
if exists == false
candidates.push(vote)
end
end
puts "The polls are now closed.\nAnd the results are in!"
candidates.each do |name|
print "#{name.capitalize}, coming in with #{voting.count(name)}"
if voting.count(name) == 1
puts " vote.\n"
else
puts " votes.\n"
end
counts << voting.count(name)
end
biggest_vote = counts.max
if counts.count(biggest_vote) > 1
puts "Well folks, we have a tie. Polls will reopen tomorrow for a re-vote!"
else
winner = candidates[counts.index(biggest_vote)]
puts "The winner is, #{winner.capitalize} coming in at #{biggest_vote} votes!"
end