0
Construct an algorithm that can read two vectors of 3 character type elements and ask the user which candidate he wants to vote for and that the result of the operation is stored on other vectors. On-screen demonstration of voting results
My attempt:
Algoritmo "eleicao"
Var
candidato: vetor[1..3] de caractere
resultado: vetor[1..3] de caractere
i: inteiro
Inicio
candidato[1] <- "maria"
candidato[2] <- "joao"
candidato[3] <- "ana"
para i de 1 ate 3 faca
escreval ("Candidatos")
escreval ("----------")
escreval ("maria, joao, ana")
escreval ()
escreval ("escolha seu candidato: ")
leia (resultado[i])
limpatela
fimpara
Fimalgoritmo
Speak Gabriel, it would be interesting for you to show what you have tried and where you are at the moment, because in the OS we are to help and not to do for you :)
– David Alves
Add the code you’ve implemented so far.
– RXSD
how I would show the accumulated result?
– Gabriel Ferreira
I believe that your vector result should be an integer vector, initialized with zeros and each vote received by the candidate[i] result[i] be increased by 1. At the end result will have the amount of votes received by each candidate. Your loop should be repeated by the total number of voters, not the number of candidates.
– anonimo