Advertisement
Unificaed

Quiz em C++

Dec 11th, 2019
1,416
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.26 KB | None | 0 0
  1. #include <stdlib.h>
  2. #include <stdio.h>
  3. #include <string.h>
  4.  
  5. struct Question{
  6. const char* Pergunta;
  7. const char* Resposta;
  8. const char* Alternativas[4];
  9. };
  10.  
  11. int main()
  12. {
  13. Question Perguntas[2];
  14.  
  15. Perguntas[0] =
  16. {
  17. "Quanto e 1+1?", //pergunta
  18. "2", //resposta
  19. {
  20. "1", "2", "3", "4" //alternativas
  21. }
  22. };
  23.  
  24. Perguntas[1] =
  25. {
  26. "Quanto e 5+1?",
  27. "6",
  28. {
  29. "1", "2", "3", "6"
  30. }
  31. };
  32.  
  33. printf("Bem-vindo ao quiz.\n");
  34.  
  35. int Resposta = 0;
  36.  
  37. while(true)
  38. {
  39.  
  40. for(int i = 0; i < _countof(Perguntas); i++)
  41. {
  42. printf("%s\n",Perguntas[i].Pergunta);
  43.  
  44. for(int j = 0; j < 4; j++)
  45. {
  46. printf("[%d] %s\n", j, Perguntas[i]. Alternativas[j]);
  47. }
  48.  
  49. printf("\nDigite: ");
  50. scanf("%i", &Resposta);
  51.  
  52. if(Resposta < 0 || Resposta > 3)
  53. {
  54. Resposta = -1;
  55. }
  56. else if(strcmp(Perguntas[i]. Alternativas[Resposta], Perguntas[i].Resposta) != 0)
  57. {
  58. Resposta = -1;
  59. }
  60.  
  61. if(Resposta == -1)
  62. {
  63. printf("\nVoce errou.\n\n");
  64. }else{
  65. printf("\nVoce acertou.\n\n");
  66. }
  67. }
  68.  
  69. }
  70.  
  71. return 0;
  72. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement