Skip to content

Conversation

@aliceboone
Copy link
Owner

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants