Update election_time #2
Open
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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!"
Input number of Voters
puts "Indicate number of voters"
voters = gets.chomp.to_i
Create array to store candidates name
array_candidates = ["Donald Duck", "Minnie Mouse", "Goofy"]
Display the array
puts "Election candidates are: #{array_candidates}"
puts "Type the name of candidate you want to vote"
Add a new candidate
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
Insert new candidate to the array
array_candidates << new_candidate
puts "Election candidates are: #{array_candidates}"
puts "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
Input 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
elsif candidate == "#{new_candidate}"
new_candidate =+ 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)"
puts "#{array_candidates[3]} - #{new_candidate} votes(s)"
Define the winner
if donald_duck > minnie_mouse && donald_duck > goofy && donald_duck
puts " Donald Duck is the winner "
elsif minnie_mouse > donald_duck && minnie_mouse > goofy && minnie_mouse
puts "Minnie Mouse is the winner "
elsif goofy > donald_duck && goofy > minnie_mouse && goofy
puts "Goofy is the winner"
elsif new_candidate > minnie_mouse && new_candidate > donald_duck && new_candidate > goofy
puts "#{array_candidates[3]} is the winner"
else goofy == minnie_mouse || goofy == donald_duck || goofy == new_candidate || minnie_mouse == donald_duck || minnie_mouse == new_candidate || donald_duck == new_candidate
puts "There has been a tie"
end
# Show the candidate who get tied
if minnie_mouse == donald_duck || minnie_mouse == goofy || minnie_mouse == new_candidate