luishenriique

QuestionĂ¡rio Cinema

Jun 5th, 2012
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 6.09 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3.  
  4. struct questionario {
  5.     int idade;
  6.     int opiniao;
  7. };
  8.  
  9. int main(){
  10.     int i, y, exibir;
  11.     int otimo = 0, bom = 0, regular = 0, ruim = 0, pessimo = 0;
  12.     float idade_otimo = 0.0, idade_bom = 0.0, idade_regular = 0.0, idade_ruim = 0.0, idade_pessimo = 0.0;
  13.     float media_idade_otimo = 0.0, media_idade_bom = 0.0, media_idade_regular = 0.0, media_idade_ruim = 0.0, media_idade_pessimo = 0.0;
  14.     float dif_percentual, percentual_otimo = 0.0, percentual_bom = 0.0, percentual_regular = 0.0, percentual_ruim = 0.0, percentual_pessimo = 0.0;
  15.     int dif_idade, maior_idade_otimo = 0, maior_idade_bom = 0, maior_idade_regular = 0, maior_idade_ruim = 0, maior_idade_pessimo = 0;
  16.     struct questionario tabela[5];
  17.  
  18.     printf("------------ QUESTIONARIO ------------\n");
  19.     printf("Qual a sua opiniao em relacao ao filme?\n\n");
  20.     printf("OPCOES:\n\n");
  21.     printf("(1) - Otimo\n");
  22.     printf("(2) - Bom\n");
  23.     printf("(3) - Regular\n");
  24.     printf("(4) - Ruim\n");
  25.     printf("(5) - Pessimo\n");
  26.  
  27.     for(i = 0; i < 5; i++){
  28.         printf("\nEspectador %d\n", i+1);
  29.         do {
  30.             printf("Idade: "); scanf("%d", &tabela[i].idade); fflush(stdin);
  31.         }while(tabela[i].idade < 1);
  32.         do {
  33.             printf("Opiniao: "); scanf("%d", &tabela[i].opiniao); fflush(stdin);
  34.         }while(tabela[i].opiniao < 1 || tabela[i].opiniao > 5);
  35.  
  36.         switch(tabela[i].opiniao){
  37.             case 1:
  38.                 otimo++;
  39.                 idade_otimo += tabela[i].idade;
  40.                 if(maior_idade_otimo < tabela[i].idade){
  41.                     maior_idade_otimo = tabela[i].idade;
  42.                 }
  43.                 break;
  44.             case 2:
  45.                 bom++;
  46.                 idade_bom += tabela[i].idade;
  47.                 if(maior_idade_bom < tabela[i].idade){
  48.                     maior_idade_bom = tabela[i].idade;
  49.                 }
  50.                 break;
  51.             case 3:
  52.                 regular++;
  53.                 idade_regular += tabela[i].idade;
  54.                 if(maior_idade_regular < tabela[i].idade){
  55.                     maior_idade_regular = tabela[i].idade;
  56.                 }
  57.                 break;
  58.             case 4:
  59.                 ruim++;
  60.                 idade_ruim += tabela[i].idade;
  61.                 if(maior_idade_ruim < tabela[i].idade){
  62.                     maior_idade_ruim = tabela[i].idade;
  63.                 }
  64.                 break;
  65.             case 5:
  66.                 pessimo++;
  67.                 idade_pessimo += tabela[i].idade;
  68.                 if(maior_idade_pessimo < tabela[i].idade){
  69.                     maior_idade_pessimo = tabela[i].idade;
  70.                 }
  71.                 break;
  72.         }
  73.     }
  74.  
  75.     system("cls");
  76.  
  77.     do{
  78.         do {
  79.             printf("O que voce deseja exibir? (0 (zero) para sair)\n\n");
  80.             printf("(1) - Quantidade de respostas otimo\n");
  81.             printf("(2) - Diferenca percentual entre as respostas bom e regular\n");
  82.             printf("(3) - Media de idade das pessoas que responderam ruim\n");
  83.             printf("(4) - Porcentagem de respostas pessimo e sua maior idade\n");
  84.             printf("(5) - Diferenca da maior idade que respondeu otimo e ruim\n");
  85.             printf("\nOpcao: "); scanf("%d", &exibir); fflush(stdin);
  86.             system("cls");
  87.         }while(exibir < 0 || exibir > 5);
  88.        
  89.         switch(exibir){
  90.         case 1:
  91.             //ITEM A
  92.             printf("Quantidade de votos:\n\n");
  93.             printf("Otimo: \t\t%d votos\n", otimo);
  94.             printf("Bom: \t\t%d votos\n", bom);
  95.             printf("Regular: \t%d votos\n", regular);
  96.             printf("Ruim: \t\t%d votos\n", ruim);
  97.             printf("Pessimo: \t%d votos\n\n", pessimo);
  98.             system("pause"); system("cls");
  99.             break;
  100.  
  101.         case 2:
  102.             //ITEM B
  103.             if(bom > 0 || regular > 0){
  104.                 if(bom > regular){
  105.                     dif_percentual = ((100.0 * bom) / (bom + regular)) - ((100.0 * regular) / (regular + bom));
  106.                 }else{
  107.                     dif_percentual = ((100.0 * regular) / (regular + bom)) - ((100.0 * bom) / (bom + regular));
  108.                 }
  109.                 printf("Diferenca percentual entre bom e regular: %.2f\%\n\n", dif_percentual);
  110.             }else{
  111.                 printf("Nao houve respostas boas ou regulares\n\n");
  112.             }
  113.             system("pause"); system("cls");
  114.             break;
  115.         case 3:
  116.             //ITEM C
  117.             printf("Media de idade das pessoas conforme sua opiniao:\n\n");
  118.             if(otimo == 0){
  119.                 printf("Otimo: \t\t0 anos (Nenhuma resposta)\n");
  120.             }else{
  121.                 media_idade_otimo = idade_otimo / otimo; printf("Otimo: \t\t%.2f anos\n", media_idade_otimo);
  122.             }
  123.             if(bom == 0){
  124.                 printf("Bom: \t\t0 anos (Nenhuma resposta)\n");
  125.             }else{
  126.                 media_idade_bom = idade_bom / bom; printf("Bom: \t\t%.2f anos\n", media_idade_bom);
  127.             }
  128.             if(regular == 0){
  129.                 printf("Regular: \t0 anos (Nenhuma resposta)\n");
  130.             }else{
  131.                 media_idade_regular = idade_regular / regular; printf("Regular: \t%.2f anos\n", media_idade_regular);
  132.             }
  133.             if(ruim == 0){
  134.                 printf("Ruim: \t\t0 anos (Nenhuma resposta)\n");
  135.             }else{
  136.                 media_idade_ruim = idade_ruim / ruim; printf("Ruim: \t\t%.2f anos\n", media_idade_ruim);
  137.             }
  138.             if(pessimo == 0){
  139.                 printf("Pessimo: \t0 anos (Nenhuma resposta)\n\n");
  140.             }else{
  141.                 media_idade_pessimo = idade_pessimo / pessimo; printf("Pessimo: \t%.2f anos\n\n", media_idade_pessimo);
  142.             }
  143.             system("pause"); system("cls");
  144.             break;
  145.         case 4:
  146.             //ITEM D
  147.             printf("Porcentagem de votos e maior idade:\n\n");
  148.             percentual_otimo = (100.0 * otimo) / 5.0; printf("Otimo: \t\t%.2f%% \t(Maior idade: %d anos)\n", percentual_otimo, maior_idade_otimo);
  149.             percentual_bom = (100.0 * bom) / 5.0; printf("Bom: \t\t%.2f%% \t(Maior idade: %d anos)\n", percentual_bom, maior_idade_bom);
  150.             percentual_regular = (100.0 * regular) / 5.0; printf("Regular: \t%.2f%% \t(Maior idade: %d anos)\n", percentual_regular, maior_idade_regular);
  151.             percentual_ruim = (100.0 * ruim) / 5.0; printf("Ruim: \t\t%.2f%% \t(Maior idade: %d anos)\n", percentual_ruim, maior_idade_ruim);
  152.             percentual_pessimo = (100.0 * pessimo) / 5.0; printf("Pessimo: \t%.2f%% \t(Maior idade: %d anos)\n\n", percentual_pessimo, maior_idade_pessimo);
  153.             system("pause"); system("cls");
  154.             break;
  155.         case 5:
  156.             //ITEM E
  157.             if(maior_idade_otimo == maior_idade_ruim){
  158.                 printf("Nao existe diferenca de idade entre a maior idade que respondeu otimo e a que respondeu ruim.\n\n");
  159.             }else{
  160.                 if(maior_idade_otimo > maior_idade_ruim){
  161.                     dif_idade = maior_idade_otimo - maior_idade_ruim;
  162.                 }else{
  163.                     dif_idade = maior_idade_ruim - maior_idade_otimo;
  164.                 }
  165.                 printf("Maior idade otimo: \t%d anos\nMaior idade ruim: \t%d anos\n", maior_idade_otimo, maior_idade_ruim);
  166.                 printf("Diferenca: \t\t%d anos\n\n", dif_idade);
  167.             }
  168.             system("pause"); system("cls");
  169.             break;
  170.         }
  171.     }while(exibir != 0);
  172.  
  173.     system("pause");
  174.     return 0;
  175. }
Advertisement
Add Comment
Please, Sign In to add comment