You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

216 lines
11 KiB

  1. #include <stdio.h>
  2. #include <stdbool.h>
  3. #include <string.h>
  4. #include <stdlib.h>
  5. #include "casualQuiz.h" //header datei
  6. void casualQuiz() {
  7. int index = 0;
  8. char* fragen[] = { //eingabe der Fragen in ein Array
  9. "Which Disney character famously leaves a glass shoe behind at a royal ball?",
  10. "The hammer and sickle are one of the most recognisable symbols of which political ideology?",
  11. "Which two words traditionally appear onscreen at the termination of a feature film?",
  12. "A person with well-developed abdominal muscles is said to have a what?",
  13. "A magnet would most likely attract which of the following?",
  14. "In the United States, what is traditionally the proper way to adress a judge?",
  15. "Which of these pairs of apps offers roughly the same type of service?",
  16. "A geologist would likely be LEAST helpful for answering questions about which of the following?",
  17. "When a person is rudely ignored, he is said to be 'getting a' what?",
  18. "A common piece of advice goes, 'Be there or be' what?",
  19. "If you're trying to find other players in a game of hide and seek, what are you most likly called?",
  20. "If you're skeptical about something, you should 'take it with a grain of' what?",
  21. "Something in an obvious location is said to be 'right under your' what?",
  22. "When a tree is cut down, the part that remains in the ground is called what?",
  23. "What name is given to the belt machinery in an airport that delivers checked luggage from the plane to baggage reclaim?",
  24. "By definition, a 10-speed bike has 10 what?",
  25. "A lullaby is a song sung to babies to help them do what?",
  26. "In history books, leaders named Alexander and Catherine both share what flattering title?",
  27. "What notable part of the US's topography accounts for roughly 20 percent of the fresh water on Earth?",
  28. "A person who is preparing to work hard is said to be 'rolling up his' what?"
  29. };
  30. char* antworten[][4] = { //Eingabe der zugehörigen Antworten in ein array
  31. {"Elsa", "Rapunzel", "Cinderella", "Pocahontas"},
  32. {"Republicanism", "Liberalism", "Conservatism", "Communism"},
  33. {"The End", "The Termination", "Pizza's ready", "Hotdog Time"},
  34. {"12-Pack", "6-Pack", "Family Pack", "One-Pack"},
  35. {"Metal", "Plastic", "Humans", "Water"},
  36. {"Your holiness", "Your eminence", "Father", "Your honor"},
  37. {"Snapchat and Instagram", "Whatsapp and Twitter(now 'X')","Lyft and Uber", "Tiktok and Spotify"},
  38. {"Granite Boulders", "Fruity Pebbles", "Precious Stones", "Igneus Rocks"},
  39. {"Hot knee","Cold shoulder", "Burning hand", "Warm toe"},
  40. {"Bare", "Aware", "Square", "All alone a usual"},
  41. {"Butterbean", "Stinky", "Dunce", "It"},
  42. {"Salt", "Sand", "Sugar", "Silicium"},
  43. {"Mattress", "Nose", "Foot", "Boxer Shorts"},
  44. {"Rump", "Leftovers", "Hump", "Stump"},
  45. {"Hangar", "Carousel", "Terminal", "Bagroller"},
  46. {"Wheels", "Spokes", "Gears", "Lives"},
  47. {"Wake up", "Eat", "Fall asleep", "Invest wisely"},
  48. {"The Great", "The Unruly", "The Ego-Consious", "The Ferocious"},
  49. {"Mark Zuckerbergs hot tub", "The Grand Canyon", "Death Valley", "The Great Lakes"},
  50. {"Sleeves", "Curtains", "AC/DC wall poster", "Towels"},
  51. };
  52. int richtigeAntworten[] = { 3,4,1,2,1,4,3,2,2,3,4,1,2,4,2,3,3,1,4,1};
  53. int length_frag_array = sizeof(richtigeAntworten) / sizeof(int); //länge des arrays wird berechnet, damit man die länge vom spiel kennt
  54. int correct = 0;
  55. int answered = 0;
  56. int* correctP = &correct; // pointer auf die zählervariable for richtige Antworten
  57. int* answeredP = &answered; // pointer auf die zählervariable for beantwortete fragen
  58. bool already_played = false; // initialisieren einer Bool variable zum abchecken ob man schon gespielt hat
  59. bool end = false;
  60. while (end == false) { //schleife, in der das Programm läuft
  61. already_played = activePlaying(fragen, *antworten, richtigeAntworten, length_frag_array, answeredP, correctP);
  62. printf("You had %d answers correct, while answering %d questions.\n", correct, answered);
  63. end = ftryAgain(already_played); //man wird gefragt ob man nochmal spielen möchte
  64. correct = 0;//zurücksetzen der beiden zählervariablen
  65. answered = 0;
  66. }
  67. return;
  68. }
  69. bool activePlaying(char* fragen[], char* antworten[], int richtige_antwort[], int size, int* answeredP, int* correctP) {
  70. int eingabe;
  71. bool richtig;
  72. int ansehen;
  73. for (int i = 0; i < size; i++) { // Schleife, die so lange läuft, je nachdem wie viele fragen es gibt
  74. eingabe = 5;
  75. richtig = false;
  76. ansehen = 0;
  77. fzeigeFragen(fragen, i); //frage wird nach gegebenem index ausgegeben
  78. fzeigeAntworten(antworten, i); //Antworten zum gleichen index wie die fragen ausgeben
  79. printf("Reminder: Typing 0 lets you stop the game.\nPlease type in your answer 1,2,3 or 4: ");
  80. eingabe = feingabeInteger(); //eingabe Funktion
  81. richtig = fcheckaufRichtigkeit(eingabe, antworten, richtige_antwort, i); //überprüfung der eingabe anhand des richtige_eingabe arrays und dem index
  82. fzaehlernachAuswahl(richtig, answeredP, correctP); // zähler werden hochgezählt je nach eingabe
  83. printf("\n----------------------------------------------------------------------------------------\n\n");
  84. }
  85. return true;
  86. }
  87. void fzeigeFragen(char* fragen[], int index) {
  88. printf("Question: %s\n", fragen[index]); //ausgabe Frage bei gegebenem index
  89. }
  90. void fzeigeAntworten(char* antworten[], int index) { //folgende ausgaben bei gegebenem index
  91. printf("1) %s\n", antworten[4 * index + 0]); //ausgabe antwort 1
  92. printf("2) %s\n", antworten[4 * index + 1]); //ausgabe antwort 2
  93. printf("3) %s\n", antworten[4 * index + 2]); //ausgabe antwort 3
  94. printf("4) %s\n", antworten[4 * index + 3]); //ausgabe antwort 4
  95. }
  96. int feingabeInteger() {
  97. int eingabe; //integer für eingabe initialisiert
  98. scanf_s("%d", &eingabe); //reine ingabe, prints sind vorher schon passiert
  99. return eingabe; // return der eingabe
  100. }
  101. bool fcheckaufRichtigkeit(int eingabe, char* antworten[], int richtige_antwort[], int i) {
  102. int ansehen = 0;
  103. switch (eingabe) {//start vom switch
  104. case 0: { //eingabe 0: abbruch funktion wird aufgerufen
  105. fabbruch();
  106. break;
  107. }
  108. case 1: {
  109. if (richtige_antwort[i] == 1) { //vergleichen vov der eingabe zu welche richtige zahl hinter dem passenden index versteckt ist
  110. printf("Right Answer, well done.\n");
  111. return true;
  112. }
  113. else {
  114. printf("Wrong answer.\n"); //wenn eingabe falsch ist
  115. printf("Would you like to know the right answer?\nInput 1 if you want to see it, 0 if not: ");
  116. scanf_s("%d", &ansehen);
  117. if (ansehen == 1) printf("The right answer was: %d) %s\n", richtige_antwort[i], antworten[4 * i + richtige_antwort[i] - 1]);
  118. else printf("Continuing...\n");
  119. }
  120. break;
  121. }
  122. case 2: {
  123. if (richtige_antwort[i] == 2) { //vergleichen vov der eingabe zu welche richtige zahl hinter dem passenden index versteckt ist
  124. printf("Right Answer, well done.\n");
  125. return true;
  126. }
  127. else {
  128. printf("Wrong answer.\n"); //wenn eingabe falsch ist
  129. printf("Would you like to know the right answer?\nInput 1 if you want to see it, 0 if not: ");
  130. scanf_s("%d", &ansehen);
  131. if (ansehen == 1) printf("The right answer was: %d) %s\n", richtige_antwort[i], antworten[4 * i + richtige_antwort[i] - 1]);
  132. else printf("Continuing...\n");
  133. }
  134. break;
  135. }
  136. case 3: {
  137. if (richtige_antwort[i] == 3) { //vergleichen vov der eingabe zu welche richtige zahl hinter dem passenden index versteckt ist
  138. printf("Right Answer, well done.\n");
  139. return true;
  140. }
  141. else {
  142. printf("Wrong answer.\n"); //wenn eingabe falsch ist
  143. printf("Would you like to know the right answer?\nInput 1 if you want to see it, 0 if not: ");
  144. scanf_s("%d", &ansehen);
  145. if (ansehen == 1) printf("The right answer was: %d) %s\n", richtige_antwort[i], antworten[4 * i + richtige_antwort[i] - 1]);
  146. else printf("Continuing...\n");
  147. }
  148. break;
  149. }
  150. case 4: {
  151. if (richtige_antwort[i] == 4) { //vergleichen vov der eingabe zu welche richtige zahl hinter dem passenden index versteckt ist
  152. printf("Right Answer, well done.\n");
  153. return true;
  154. }
  155. else {
  156. printf("Wrong answer.\n"); //wenn eingabe falsch ist
  157. printf("Would you like to know the right answer?\nInput 1 if you want to see it, 0 if not: ");
  158. scanf_s("%d", &ansehen);
  159. if (ansehen == 1) printf("The right answer was: %d) %s\n", richtige_antwort[i], antworten[4 * i + richtige_antwort[i] - 1]);
  160. else printf("Continuing...\n");
  161. }
  162. break;
  163. }
  164. default: { // eingabe war was anderes als 1,2,3,4 oder 5
  165. printf("Wrong Input! Going to the next question...\n");
  166. return false;
  167. break;
  168. }
  169. }
  170. return false;
  171. }
  172. void fzaehlernachAuswahl(bool richtig, int* answeredP, int* correctP) {
  173. if (richtig == true) { //wenn dei eingabe von vorhin richtig war
  174. *answeredP = *answeredP + 1; //hochzählen von der zählervariablen für beantwortete fragen um 1
  175. *correctP = *correctP + 1; //hochzählen von der zählervariablen für korrekte antworten um 1
  176. }
  177. else { //wenn die eingabe von vorhin falsch war
  178. *answeredP = *answeredP + 1; //hochzählen von der zählervariablen für beantwortete fragen um 1
  179. }
  180. return;
  181. }
  182. bool ftryAgain(bool already_played) {
  183. if (already_played == true) { //wenn man das spiel schon gespielt hat
  184. int sure;
  185. printf("Would you like to play again?\n");
  186. printf("Input 1 to continue gaming, input 0 to close the game: ");
  187. scanf_s("%d", &sure); //eingabe pb man das spiel nochmal spielen möchte
  188. if (sure == 1) { // nochmal spielen
  189. printf("Starting the program up again...");
  190. return false;
  191. }
  192. else { //beenden
  193. printf("Input not '1', returning to main menu...");
  194. return true;
  195. }
  196. }
  197. else { //wenn man das spiel warum auch immer noch nicht gespielt hat
  198. printf("It looks like you havent played the program yet, starting it up...");
  199. return false;
  200. }
  201. }
  202. void fabbruch() {
  203. int wirklich;
  204. printf("Do you really want to close the program?\nInput 1 to exit, input 0 to continue gaming: ");
  205. scanf_s("%d", &wirklich); //eingabe ob man denn wirklich das programm beenden möchte
  206. if (wirklich == 1) exit(7); //ende mit code 7
  207. else return;//frage wird übersprungen, aber programm läuft weiter
  208. }