Advertisement
Guest User

Quiz

a guest
Feb 28th, 2011
674
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.43 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <strings.h>
  4. #include <ctype.h>
  5.  
  6. struct Perguntas {
  7.    char texto[200];
  8.    char resposta_correta;
  9.    int pontos;            
  10. };
  11.  
  12. struct Teste {
  13.    struct Perguntas perguntas[10];
  14.    char resposta[10];
  15. };
  16.  
  17. int main() {
  18.    struct Teste teste;
  19.    system("cls");
  20.    printf("Bem vindo ao teste!!!\n");
  21.    strcpy(teste.perguntas[0].texto,"\n\nPrintf eh um:\na)erro de codificacao\nb)com.de entrada de dados\nc)com.de saida de dados");
  22.    teste.perguntas[0].resposta_correta = 'C';
  23.    teste.perguntas[0].pontos = 2;
  24.    strcpy(teste.perguntas[1].texto,"\n\nScanf eh um:\na)erro de codificacao\nb)com.de entrada de dados\nc)com.de saida de dados");
  25.    teste.perguntas[1].resposta_correta = 'B';
  26.    teste.perguntas[1].pontos = 1;      
  27.    strcpy(teste.perguntas[2].texto,"\n\nError eh um:\na)erro de codificacao\nb)com.de entrada de dados\nc)com.de saida de dados");
  28.    teste.perguntas[2].resposta_correta = 'A';
  29.    teste.perguntas[2].pontos = 3;  
  30.    
  31.    int i;
  32.    for(i=0;i<3;i++) {
  33.       printf("%s \n\nResposta .: ",teste.perguntas[i].texto);
  34.       teste.resposta[i] = getche();
  35.    }
  36.    int totalpontos = 0;
  37.    for(i=0;i<3;i++) {
  38.       if (teste.perguntas[i].resposta_correta == toupper(teste.resposta[i]))
  39.          totalpontos = totalpontos + teste.perguntas[i].pontos;
  40.    }
  41.    printf("\n\nO total de pontos acumulados foi %i . \n\n",totalpontos);
  42.    system("pause");
  43.    return 0;
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement