Advertisement
Guest User

Untitled

a guest
Nov 12th, 2019
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.83 KB | None | 0 0
  1. /******************************************************************************
  2.  
  3. Welcome to GDB Online.
  4. GDB online is an online compiler and debugger tool for C, C++, Python, Java, PHP, Ruby, Perl,
  5. C#, VB, Swift, Pascal, Fortran, Haskell, Objective-C, Assembly, HTML, CSS, JS, SQLite, Prolog.
  6. Code, Compile, Run and Debug online from anywhere in world.
  7.  
  8. *******************************************************************************/
  9. #include <stdio.h>
  10.  
  11. int main()
  12. {
  13. // make answer variables
  14. char ans1, ans2, ans3, ans4, ans5;
  15.  
  16. // ask 5 math questions and read in a character input
  17. printf("What is 5+2?\n");
  18. printf("a. 6\n");
  19. printf("b. 7\n");
  20. printf("c. 3\n");
  21. printf("d. 2\n");
  22. printf("e. 1\n");
  23. scanf("%s", &ans1);
  24.  
  25. printf("What is 10+3?\n");
  26. printf("a. 13\n");
  27. printf("b. 7\n");
  28. printf("c. 12\n");
  29. printf("d. 4\n");
  30. printf("e. 2\n");
  31. scanf("%s", &ans2);
  32.  
  33. printf("What is 9/3?\n");
  34. printf("a. 0\n");
  35. printf("b. 1\n");
  36. printf("c. 4\n");
  37. printf("d. 3\n");
  38. printf("e. 9\n");
  39. scanf("%s", &ans3);
  40.  
  41. printf("What is 5-2?\n");
  42. printf("a. 6\n");
  43. printf("b. 7\n");
  44. printf("c. 3\n");
  45. printf("d. 2\n");
  46. printf("e. 52\n");
  47. scanf("%s", &ans4);
  48.  
  49. printf("What is 2*4?\n");
  50. printf("a. 0\n");
  51. printf("b. 7\n");
  52. printf("c. 3\n");
  53. printf("d. 8\n");
  54. printf("e. 6\n");
  55. scanf("%s", &ans5);
  56.  
  57. // store a counter and count how many are correct
  58. int cnt = 0;
  59. if(ans1=='b') cnt++;
  60. if(ans2=='a') cnt++;
  61. if(ans3=='d') cnt++;
  62. if(ans4=='c') cnt++;
  63. if(ans5=='d') cnt++;
  64.  
  65. // output the numbr of correct answers and the percentage of correct answers
  66. printf("The number of correct answers out of 5 is: %d\n", cnt);
  67. printf("Your percentage is: %d\n.", cnt*100/5);
  68.  
  69.  
  70. return 0;
  71. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement