Advertisement
Guest User

Duvida em C

a guest
May 21st, 2018
282
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.79 KB | None | 0 0
  1. #include <stdio.h>
  2.  
  3. int main(int argc, char const *argv[])
  4. {
  5.     int voto = 0;
  6.     int votantes = 0;
  7.     int opc1 = 0, opc2 = 0, opc3 = 0, opc4 = 0, opc5 = 0, opc6 = 0;
  8.     int percent1 = 0, percent2 = 0, percent3 = 0, percent4 = 0, percent5 = 0, percent6 = 0;
  9.     int i = 0;
  10.  
  11.  
  12.     printf("Insira a quantidade de pessoas que irao votar\n");
  13.     scanf("%d", &votantes);
  14.  
  15.     for(i = 0; i < votantes; i++)
  16.     {
  17.     printf("Qual a melhor unidade para servers (Votante numero %d) \n", i+1);
  18.     printf("1 - Windows server\n");
  19.     printf("2 - Unix\n");
  20.     printf("3 - linux\n");
  21.     printf("4 - netware\n");
  22.     printf("5- mac\n");
  23.     printf("6 - outro\n");
  24.     scanf("%d", &voto);
  25.  
  26.     switch(voto){
  27.  
  28.         case 1:
  29.         printf("Voto registrado opc 1\n");
  30.         opc1++;
  31.         break;
  32.  
  33.         case 2:
  34.         printf("Voto registrado opc 2\n");
  35.         opc2++;
  36.         break;
  37.  
  38.         case 3:
  39.         printf("Voto registrado opc 3\n");
  40.         opc3++;
  41.         break;
  42.  
  43.         case 4:
  44.         printf("Voto registrado opc 4\n");
  45.         opc4++;
  46.         break;
  47.  
  48.         case 5:
  49.         printf("Voto registrado opc 5\n");
  50.         opc5++;
  51.         break;
  52.  
  53.         case 6:
  54.         printf("Voto registrado opc 6\n");
  55.         opc6++;
  56.         break;
  57.  
  58.         default:
  59.        printf ("Valor invalido!\n");
  60.  
  61.     }
  62.  
  63.  
  64.  
  65.  
  66.  
  67. }
  68.  
  69.      percent1 = (opc1 / votantes) * 100;
  70.      percent2 = (opc2 / votantes) * 100;
  71.      percent3 = (opc3 / votantes) * 100;
  72.      percent4 = (opc4 / votantes) * 100;
  73.      percent5 = (opc5 / votantes) * 100;
  74.      percent6 = (opc6 / votantes) * 100;
  75.  
  76.  
  77.     printf("[Windows server] %d votos e %d porcento\n", opc1, percent1);
  78.     printf("[Unix] %d votos e %d porcento\n", opc2, percent2);
  79.     printf("[Linux] %d votos e %d porcento\n", opc3, percent3);
  80.     printf("[Netware] %d votos e %d porcento\n", opc4, percent4);
  81.     printf("[Mac OS] %d votos e %d porcento\n", opc5, percent5);
  82.     printf("[Outros] %d votos e %d porcento\n", opc6, percent6);
  83.  
  84.     return 0;
  85. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement