-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathelection_time
88 lines (66 loc) · 2.3 KB
/
election_time
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
# Define the variables
candidate = 0
vote = 0
donald_duck = 0
minnie_mouse = 0
goofy = 0
new_candidate = 0
# Information to the user about election and candidates
puts "Welcome to my election vote program!"
puts "Indicate number of voters"
voters = gets.chomp.to_i
array_candidates = ["Donald Duck", "Minnie Mouse", "Goofy"]
puts "Election candidates are: #{array_candidates} type the name of candidate you want to vote"
puts "Do you want to add a new candidate"
add_new = gets.chomp
if add_new == "yes"
puts "Add the new candidate name"
new_candidate = gets.chomp.to_s
array_candidates << new_candidate
puts "Election candidates are: #{array_candidates} type the name of candidate you want to vote"
else
puts "Election candidates are: #{array_candidates} type the name of candidate you want to vote"
end
# Imput user vote
(1..voters).each do|candidate|
candidate = gets.chomp.downcase
vote += 1
puts "Vote # #{vote}: <#{candidate}>"
# Check candidates and add votes to them
if candidate == "donald duck"
donald_duck = donald_duck + 1
elsif candidate == "minnie mouse"
minnie_mouse = minnie_mouse + 1
elsif candidate == "goofy"
goofy = goofy + 1
end
end
# Show the election results
puts "RESULTS...."
puts "Votes Summary:"
puts "Donald Duck - #{donald_duck} votes(s)"
puts "Minnie Mouse - #{minnie_mouse} votes(s)"
puts "Goofy - #{goofy} votes(s)"
# Define the winner
if donald_duck > minnie_mouse && donald_duck > goofy
puts "Donald Duck is the winner"
elsif minnie_mouse > donald_duck && minnie_mouse > goofy
puts "Minnie Mouse is the winner"
elsif goofy > donald_duck && goofy > minnie_mouse
puts "Goofy is the winner"
else goofy == minnie_mouse || goofy == donald_duck || donald_duck == minnie_mouse
puts "There has been a tie"
end
puts "Donald Duck - #{donald_duck} votes(s)"
puts "Minnie Mouse - #{minnie_mouse} votes(s)"
puts "Goofy - #{goofy} votes(s)"
# Define the winner
if donald_duck > minnie_mouse && donald_duck > goofy
puts "Donald Duck is the winner"
elsif minnie_mouse > donald_duck && minnie_mouse > goofy
puts "Minnie Mouse is the winner"
elsif goofy > donald_duck && goofy > minnie_mouse
puts "Goofy is the winner"
else goofy == minnie_mouse || goofy == donald_duck || donald_duck == minnie_mouse
puts "There has been a tie"
end