Last active
December 6, 2016 12:54
-
-
Save paolorotolo/62ea724473da328cc7c31d17e500561c to your computer and use it in GitHub Desktop.
voti.m
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
numeroVotanti = input('Quanti sono i votanti: '); | |
votoSi = 0; | |
votoNo = 0; | |
votoNonSo = 0; | |
nonVoto = 0; | |
for i=1:numeroVotanti | |
k = input('[1 - SÌ, 2 - NO, 3 - NON SO, 4 - NON RISPONDO]'); | |
if k == 1 | |
votoSi = votoSi + 1; | |
elseif k == 2 | |
votoNo = votoNo + 1; | |
elseif k == 3 | |
votoNonSo = votoNonSo + 1; | |
elseif k == 4 | |
nonVoto = nonVoto +1; | |
end | |
end | |
disp(votoSi); | |
disp(votoNo); | |
disp('Il'); | |
disp(percentuale(votoNonSo, numeroVotanti)); | |
disp('ha votato non so'); | |
percentuale(nonVoto, numeroVotanti) | |
function a = percentuale(voti, totale) | |
a = voti * 100 / totale; | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment