Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- struct questionario {
- int idade;
- int opiniao;
- };
- int main(){
- int i, y, exibir;
- int otimo = 0, bom = 0, regular = 0, ruim = 0, pessimo = 0;
- float idade_otimo = 0.0, idade_bom = 0.0, idade_regular = 0.0, idade_ruim = 0.0, idade_pessimo = 0.0;
- 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;
- float dif_percentual, percentual_otimo = 0.0, percentual_bom = 0.0, percentual_regular = 0.0, percentual_ruim = 0.0, percentual_pessimo = 0.0;
- int dif_idade, maior_idade_otimo = 0, maior_idade_bom = 0, maior_idade_regular = 0, maior_idade_ruim = 0, maior_idade_pessimo = 0;
- struct questionario tabela[5];
- printf("------------ QUESTIONARIO ------------\n");
- printf("Qual a sua opiniao em relacao ao filme?\n\n");
- printf("OPCOES:\n\n");
- printf("(1) - Otimo\n");
- printf("(2) - Bom\n");
- printf("(3) - Regular\n");
- printf("(4) - Ruim\n");
- printf("(5) - Pessimo\n");
- for(i = 0; i < 5; i++){
- printf("\nEspectador %d\n", i+1);
- do {
- printf("Idade: "); scanf("%d", &tabela[i].idade); fflush(stdin);
- }while(tabela[i].idade < 1);
- do {
- printf("Opiniao: "); scanf("%d", &tabela[i].opiniao); fflush(stdin);
- }while(tabela[i].opiniao < 1 || tabela[i].opiniao > 5);
- switch(tabela[i].opiniao){
- case 1:
- otimo++;
- idade_otimo += tabela[i].idade;
- if(maior_idade_otimo < tabela[i].idade){
- maior_idade_otimo = tabela[i].idade;
- }
- break;
- case 2:
- bom++;
- idade_bom += tabela[i].idade;
- if(maior_idade_bom < tabela[i].idade){
- maior_idade_bom = tabela[i].idade;
- }
- break;
- case 3:
- regular++;
- idade_regular += tabela[i].idade;
- if(maior_idade_regular < tabela[i].idade){
- maior_idade_regular = tabela[i].idade;
- }
- break;
- case 4:
- ruim++;
- idade_ruim += tabela[i].idade;
- if(maior_idade_ruim < tabela[i].idade){
- maior_idade_ruim = tabela[i].idade;
- }
- break;
- case 5:
- pessimo++;
- idade_pessimo += tabela[i].idade;
- if(maior_idade_pessimo < tabela[i].idade){
- maior_idade_pessimo = tabela[i].idade;
- }
- break;
- }
- }
- system("cls");
- do{
- do {
- printf("O que voce deseja exibir? (0 (zero) para sair)\n\n");
- printf("(1) - Quantidade de respostas otimo\n");
- printf("(2) - Diferenca percentual entre as respostas bom e regular\n");
- printf("(3) - Media de idade das pessoas que responderam ruim\n");
- printf("(4) - Porcentagem de respostas pessimo e sua maior idade\n");
- printf("(5) - Diferenca da maior idade que respondeu otimo e ruim\n");
- printf("\nOpcao: "); scanf("%d", &exibir); fflush(stdin);
- system("cls");
- }while(exibir < 0 || exibir > 5);
- switch(exibir){
- case 1:
- //ITEM A
- printf("Quantidade de votos:\n\n");
- printf("Otimo: \t\t%d votos\n", otimo);
- printf("Bom: \t\t%d votos\n", bom);
- printf("Regular: \t%d votos\n", regular);
- printf("Ruim: \t\t%d votos\n", ruim);
- printf("Pessimo: \t%d votos\n\n", pessimo);
- system("pause"); system("cls");
- break;
- case 2:
- //ITEM B
- if(bom > 0 || regular > 0){
- if(bom > regular){
- dif_percentual = ((100.0 * bom) / (bom + regular)) - ((100.0 * regular) / (regular + bom));
- }else{
- dif_percentual = ((100.0 * regular) / (regular + bom)) - ((100.0 * bom) / (bom + regular));
- }
- printf("Diferenca percentual entre bom e regular: %.2f\%\n\n", dif_percentual);
- }else{
- printf("Nao houve respostas boas ou regulares\n\n");
- }
- system("pause"); system("cls");
- break;
- case 3:
- //ITEM C
- printf("Media de idade das pessoas conforme sua opiniao:\n\n");
- if(otimo == 0){
- printf("Otimo: \t\t0 anos (Nenhuma resposta)\n");
- }else{
- media_idade_otimo = idade_otimo / otimo; printf("Otimo: \t\t%.2f anos\n", media_idade_otimo);
- }
- if(bom == 0){
- printf("Bom: \t\t0 anos (Nenhuma resposta)\n");
- }else{
- media_idade_bom = idade_bom / bom; printf("Bom: \t\t%.2f anos\n", media_idade_bom);
- }
- if(regular == 0){
- printf("Regular: \t0 anos (Nenhuma resposta)\n");
- }else{
- media_idade_regular = idade_regular / regular; printf("Regular: \t%.2f anos\n", media_idade_regular);
- }
- if(ruim == 0){
- printf("Ruim: \t\t0 anos (Nenhuma resposta)\n");
- }else{
- media_idade_ruim = idade_ruim / ruim; printf("Ruim: \t\t%.2f anos\n", media_idade_ruim);
- }
- if(pessimo == 0){
- printf("Pessimo: \t0 anos (Nenhuma resposta)\n\n");
- }else{
- media_idade_pessimo = idade_pessimo / pessimo; printf("Pessimo: \t%.2f anos\n\n", media_idade_pessimo);
- }
- system("pause"); system("cls");
- break;
- case 4:
- //ITEM D
- printf("Porcentagem de votos e maior idade:\n\n");
- percentual_otimo = (100.0 * otimo) / 5.0; printf("Otimo: \t\t%.2f%% \t(Maior idade: %d anos)\n", percentual_otimo, maior_idade_otimo);
- percentual_bom = (100.0 * bom) / 5.0; printf("Bom: \t\t%.2f%% \t(Maior idade: %d anos)\n", percentual_bom, maior_idade_bom);
- percentual_regular = (100.0 * regular) / 5.0; printf("Regular: \t%.2f%% \t(Maior idade: %d anos)\n", percentual_regular, maior_idade_regular);
- percentual_ruim = (100.0 * ruim) / 5.0; printf("Ruim: \t\t%.2f%% \t(Maior idade: %d anos)\n", percentual_ruim, maior_idade_ruim);
- percentual_pessimo = (100.0 * pessimo) / 5.0; printf("Pessimo: \t%.2f%% \t(Maior idade: %d anos)\n\n", percentual_pessimo, maior_idade_pessimo);
- system("pause"); system("cls");
- break;
- case 5:
- //ITEM E
- if(maior_idade_otimo == maior_idade_ruim){
- printf("Nao existe diferenca de idade entre a maior idade que respondeu otimo e a que respondeu ruim.\n\n");
- }else{
- if(maior_idade_otimo > maior_idade_ruim){
- dif_idade = maior_idade_otimo - maior_idade_ruim;
- }else{
- dif_idade = maior_idade_ruim - maior_idade_otimo;
- }
- printf("Maior idade otimo: \t%d anos\nMaior idade ruim: \t%d anos\n", maior_idade_otimo, maior_idade_ruim);
- printf("Diferenca: \t\t%d anos\n\n", dif_idade);
- }
- system("pause"); system("cls");
- break;
- }
- }while(exibir != 0);
- system("pause");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment