Florian Baeseler
11 months ago
4 changed files with 181 additions and 92 deletions
-
BINbuild/test/out/c/casualQuiz.o
-
214src/casualQuiz.c
-
12src/casualQuiz.h
-
35test/test_casualQuiz.c
@ -1,145 +1,217 @@ |
|||||
#include <stdio.h> |
#include <stdio.h> |
||||
#include <stdbool.h> |
#include <stdbool.h> |
||||
#include <string.h> |
#include <string.h> |
||||
|
#include <stdlib.h> |
||||
|
|
||||
#include "casualQuiz.h" |
|
||||
|
#include "casualQuiz.h" //header datei |
||||
|
|
||||
|
|
||||
void casualQuiz() { |
void casualQuiz() { |
||||
printf("Print aus der Funktion Casual Quiz"); |
|
||||
int index = 0; |
int index = 0; |
||||
char* easy_fragen[] = { //eingabe der Fragen in ein Array |
|
||||
|
char* fragen[] = { //eingabe der Fragen in ein Array |
||||
"Which Disney character famously leaves a glass shoe behind at a royal ball?", |
"Which Disney character famously leaves a glass shoe behind at a royal ball?", |
||||
"The hammer and sickle are one of the most recognisable symbols of which political ideology?", |
"The hammer and sickle are one of the most recognisable symbols of which political ideology?", |
||||
"Which two words traditionally appear onscreen at the termination of a feature film?", |
"Which two words traditionally appear onscreen at the termination of a feature film?", |
||||
"A person with well-developed abdominal muscles is said to have a what?", |
"A person with well-developed abdominal muscles is said to have a what?", |
||||
"A magnet would most likely attract which of the following?", |
"A magnet would most likely attract which of the following?", |
||||
|
"In the United States, what is traditionally the proper way to adress a judge?", |
||||
|
"Which of these pairs of apps offers roughly the same type of service?", |
||||
|
"A geologist would likely be LEAST helpful for answering questions about which of the following?", |
||||
|
"When a person is rudely ignored, he is said to be 'getting a' what?", |
||||
|
"A common piece of advice goes, 'Be there or be' what?", |
||||
|
"If you're trying to find other players in a game of hide and seek, what are you most likly called?", |
||||
|
"If you're skeptical about something, you should 'take it with a grain of' what?", |
||||
|
"Something in an obvious location is said to be 'right under your' what?", |
||||
|
"When a tree is cut down, the part that remains in the ground is called what?", |
||||
|
"What name is given to the belt machinery in an airport that delivers checked luggage from the plane to baggage reclaim?", |
||||
|
"By definition, a 10-speed bike has 10 what?", |
||||
|
"A lullaby is a song sung to babies to help them do what?", |
||||
|
"In history books, leaders named Alexander and Catherine both share what flattering title?", |
||||
|
"What notable part of the US's topography accounts for roughly 20 percent of the fresh water on Earth?", |
||||
|
"A person who is preparing to work hard is said to be 'rolling up his' what?" |
||||
}; |
}; |
||||
char* easy_antworten[][4] = { //Eingabe der zugehörigen Antworten in ein array |
|
||||
|
char* antworten[][4] = { //Eingabe der zugehörigen Antworten in ein array |
||||
{"Elsa", "Rapunzel", "Cinderella", "Pocahontas"}, |
{"Elsa", "Rapunzel", "Cinderella", "Pocahontas"}, |
||||
{"Republicanism", "Liberalism", "Conservatism", "Communism"}, |
{"Republicanism", "Liberalism", "Conservatism", "Communism"}, |
||||
{"The End", "The Termination", "Pizza's ready", "Hotdog Time"}, |
{"The End", "The Termination", "Pizza's ready", "Hotdog Time"}, |
||||
{"12-Pack", "6-Pack", "Family Pack", "One-Pack"}, |
{"12-Pack", "6-Pack", "Family Pack", "One-Pack"}, |
||||
{"Metal", "Plastic", "Humans", "Water"}, |
{"Metal", "Plastic", "Humans", "Water"}, |
||||
|
{"Your holiness", "Your eminence", "Father", "Your honor"}, |
||||
|
{"Snapchat and Instagram", "Whatsapp and Twitter(now 'X')","Lyft and Uber", "Tiktok and Spotify"}, |
||||
|
{"Granite Boulders", "Fruity Pebbles", "Precious Stones", "Igneus Rocks"}, |
||||
|
{"Hot knee","Cold shoulder", "Burning hand", "Warm toe"}, |
||||
|
{"Bare", "Aware", "Square", "All alone a usual"}, |
||||
|
{"Butterbean", "Stinky", "Dunce", "It"}, |
||||
|
{"Salt", "Sand", "Sugar", "Silicium"}, |
||||
|
{"Mattress", "Nose", "Foot", "Boxer Shorts"}, |
||||
|
{"Rump", "Leftovers", "Hump", "Stump"}, |
||||
|
{"Hangar", "Carousel", "Terminal", "Bagroller"}, |
||||
|
{"Wheels", "Spokes", "Gears", "Lives"}, |
||||
|
{"Wake up", "Eat", "Fall asleep", "Invest wisely"}, |
||||
|
{"The Great", "The Unruly", "The Ego-Consious", "The Ferocious"}, |
||||
|
{"Mark Zuckerbergs hot tub", "The Grand Canyon", "Death Valley", "The Great Lakes"}, |
||||
|
{"Sleeves", "Curtains", "AC/DC wall poster", "Towels"}, |
||||
|
|
||||
}; |
|
||||
int easy_richtigeAntworten[] = { 3,4,1,2,1 }; // int, um die jeweils richtige antwort zu zeigen |
|
||||
|
|
||||
int length_frag_array = sizeof(easy_richtigeAntworten) / sizeof(int); |
|
||||
|
}; |
||||
|
int richtigeAntworten[] = { 3,4,1,2,1,4,3,2,2,3,4,1,2,4,2,3,3,1,4,1}; |
||||
|
int length_frag_array = sizeof(richtigeAntworten) / sizeof(int); //länge des arrays wird berechnet, damit man die länge vom spiel kennt |
||||
int correct = 0; |
int correct = 0; |
||||
int answered = 0; |
int answered = 0; |
||||
int* correctP = &correct; |
|
||||
int* answeredP = &answered; |
|
||||
bool already_played = false; |
|
||||
|
int* correctP = &correct; // pointer auf die zählervariable for richtige Antworten |
||||
|
int* answeredP = &answered; // pointer auf die zählervariable for beantwortete fragen |
||||
|
bool already_played = false; // initialisieren einer Bool variable zum abchecken ob man schon gespielt hat |
||||
bool end = false; |
bool end = false; |
||||
while (end == false) { |
|
||||
already_played = activePlaying(easy_fragen, *easy_antworten, easy_richtigeAntworten, length_frag_array, answeredP, correctP); |
|
||||
printf("korrekte Antworten: %d\n", correct); |
|
||||
printf("bei: %d beantworteten Fragen", answered); |
|
||||
correct = 0; |
|
||||
|
while (end == false) { //schleife, in der das Programm läuft |
||||
|
already_played = activePlaying(fragen, *antworten, richtigeAntworten, length_frag_array, answeredP, correctP); |
||||
|
printf("You had %d answers correct, while answering %d questions.\n", correct, answered); |
||||
|
end = ftryAgain(already_played); //man wird gefragt ob man nochmal spielen möchte |
||||
|
correct = 0;//zurücksetzen der beiden zählervariablen |
||||
answered = 0; |
answered = 0; |
||||
if (already_played == true) { |
|
||||
int sure; |
|
||||
printf("Would you like to play again?\n"); |
|
||||
printf("Input 1 to continue Gaming, input 0 to return to the main menu: "); |
|
||||
scanf_s("%d", &sure); |
|
||||
|
|
||||
if (sure == 1) printf("Starting the program up again..."); |
|
||||
else { |
|
||||
printf("Input not '1', returning to main menu..."); |
|
||||
end = true; |
|
||||
} |
|
||||
} |
|
||||
} |
} |
||||
return; |
return; |
||||
} |
} |
||||
bool activePlaying(char* fragen[], char* antworten[], int richtige_antwort[], int size, int* answeredP, int* correctP) { |
bool activePlaying(char* fragen[], char* antworten[], int richtige_antwort[], int size, int* answeredP, int* correctP) { |
||||
int eingabe; |
int eingabe; |
||||
bool richtig; |
bool richtig; |
||||
for (int i = 0; i < size; i++) { |
|
||||
|
int ansehen; |
||||
|
for (int i = 0; i < size; i++) { // Schleife, die so lange läuft, je nachdem wie viele fragen es gibt |
||||
eingabe = 5; |
eingabe = 5; |
||||
richtig = false; |
richtig = false; |
||||
FzeigeFragen(fragen, i); |
|
||||
FzeigeAntworten(antworten, i); |
|
||||
printf("Please type in your answer 1,2,3 or 4: "); |
|
||||
eingabe = FEingabeInteger(); |
|
||||
richtig = FcheckaufRichtigkeit(eingabe, richtige_antwort, i); |
|
||||
FzaehlernachAuswahl(richtig, answeredP, correctP); |
|
||||
printf("Bool richtig / falsch: %d\n", richtig); |
|
||||
printf(" %d\n", richtige_antwort[i]); |
|
||||
|
ansehen = 0; |
||||
|
fzeigeFragen(fragen, i); //frage wird nach gegebenem index ausgegeben |
||||
|
fzeigeAntworten(antworten, i); //Antworten zum gleichen index wie die fragen ausgeben |
||||
|
printf("Reminder: Typing 0 lets you stop the game.\nPlease type in your answer 1,2,3 or 4: "); |
||||
|
eingabe = feingabeInteger(); //eingabe Funktion |
||||
|
richtig = fcheckaufRichtigkeit(eingabe, antworten, richtige_antwort, i); //überprüfung der eingabe anhand des richtige_eingabe arrays und dem index |
||||
|
fzaehlernachAuswahl(richtig, answeredP, correctP); // zähler werden hochgezählt je nach eingabe |
||||
|
printf("\n----------------------------------------------------------------------------------------\n\n"); |
||||
|
|
||||
} |
} |
||||
return true; |
return true; |
||||
} |
} |
||||
void FzeigeFragen(char* fragen[], int index) { |
|
||||
printf("Question: %s\n", fragen[index]); |
|
||||
|
void fzeigeFragen(char* fragen[], int index) { |
||||
|
printf("Question: %s\n", fragen[index]); //ausgabe Frage bei gegebenem index |
||||
} |
} |
||||
void FzeigeAntworten(char* antworten[], int index) { |
|
||||
printf("1) %s\n", antworten[4 * index + 0]); |
|
||||
printf("2) %s\n", antworten[4 * index + 1]); |
|
||||
printf("3) %s\n", antworten[4 * index + 2]); |
|
||||
printf("4) %s\n", antworten[4 * index + 3]); |
|
||||
|
void fzeigeAntworten(char* antworten[], int index) { //folgende ausgaben bei gegebenem index |
||||
|
printf("1) %s\n", antworten[4 * index + 0]); //ausgabe antwort 1 |
||||
|
printf("2) %s\n", antworten[4 * index + 1]); //ausgabe antwort 2 |
||||
|
printf("3) %s\n", antworten[4 * index + 2]); //ausgabe antwort 3 |
||||
|
printf("4) %s\n", antworten[4 * index + 3]); //ausgabe antwort 4 |
||||
} |
} |
||||
int FEingabeInteger() { |
|
||||
int eingabeInt; |
|
||||
scanf_s("%d", &eingabeInt); |
|
||||
return eingabeInt; |
|
||||
|
int feingabeInteger() { |
||||
|
int eingabe; //integer für eingabe initialisiert |
||||
|
scanf_s("%d", &eingabe); //reine ingabe, prints sind vorher schon passiert |
||||
|
return eingabe; // return der eingabe |
||||
} |
} |
||||
bool FcheckaufRichtigkeit(int eingabe, int richtige_antwort[], int i) { |
|
||||
switch (eingabe) { |
|
||||
|
bool fcheckaufRichtigkeit(int eingabe, char* antworten[], int richtige_antwort[], int i) { |
||||
|
int ansehen = 0; |
||||
|
switch (eingabe) {//start vom switch |
||||
|
case 0: { //eingabe 0: abbruch funktion wird aufgerufen |
||||
|
fabbruch(); |
||||
|
break; |
||||
|
} |
||||
case 1: { |
case 1: { |
||||
printf("Case 1\n"); |
|
||||
if (richtige_antwort[i] == 1) { |
|
||||
|
if (richtige_antwort[i] == 1) { //vergleichen vov der eingabe zu welche richtige zahl hinter dem passenden index versteckt ist |
||||
printf("Right Answer, well done.\n"); |
printf("Right Answer, well done.\n"); |
||||
return true; |
return true; |
||||
} |
} |
||||
else printf("Wrong answer.\n"); |
|
||||
|
else { |
||||
|
printf("Wrong answer.\n"); //wenn eingabe falsch ist |
||||
|
printf("Would you like to know the right answer?\nInput 1 if you want to see it, 0 if not: "); |
||||
|
scanf_s("%d", &ansehen); |
||||
|
if (ansehen == 1) printf("The right answer was: %d) %s\n", richtige_antwort[i], antworten[4 * i + richtige_antwort[i] - 1]); |
||||
|
else printf("Continuing...\n"); |
||||
|
} |
||||
break; |
break; |
||||
} |
} |
||||
case 2: { |
case 2: { |
||||
printf("Case 2\n"); |
|
||||
if (richtige_antwort[i] == 2) { |
|
||||
|
if (richtige_antwort[i] == 2) { //vergleichen vov der eingabe zu welche richtige zahl hinter dem passenden index versteckt ist |
||||
printf("Right Answer, well done.\n"); |
printf("Right Answer, well done.\n"); |
||||
return true; |
return true; |
||||
} |
} |
||||
else printf("Wrong answer.\n"); |
|
||||
|
else { |
||||
|
printf("Wrong answer.\n"); //wenn eingabe falsch ist |
||||
|
printf("Would you like to know the right answer?\nInput 1 if you want to see it, 0 if not: "); |
||||
|
scanf_s("%d", &ansehen); |
||||
|
if (ansehen == 1) printf("The right answer was: %d) %s\n", richtige_antwort[i], antworten[4 * i + richtige_antwort[i] - 1]); |
||||
|
else printf("Continuing...\n"); |
||||
|
} |
||||
break; |
break; |
||||
} |
} |
||||
case 3: { |
case 3: { |
||||
printf("Case 3\n"); |
|
||||
if (richtige_antwort[i] == 3) { |
|
||||
|
if (richtige_antwort[i] == 3) { //vergleichen vov der eingabe zu welche richtige zahl hinter dem passenden index versteckt ist |
||||
printf("Right Answer, well done.\n"); |
printf("Right Answer, well done.\n"); |
||||
return true; |
return true; |
||||
} |
} |
||||
else printf("Wrong answer.\n"); |
|
||||
|
else { |
||||
|
printf("Wrong answer.\n"); //wenn eingabe falsch ist |
||||
|
printf("Would you like to know the right answer?\nInput 1 if you want to see it, 0 if not: "); |
||||
|
scanf_s("%d", &ansehen); |
||||
|
if (ansehen == 1) printf("The right answer was: %d) %s\n", richtige_antwort[i], antworten[4 * i + richtige_antwort[i] - 1]); |
||||
|
else printf("Continuing...\n"); |
||||
|
} |
||||
break; |
break; |
||||
} |
} |
||||
case 4: { |
case 4: { |
||||
printf("Case 4\n"); |
|
||||
if (richtige_antwort[i] == 4) { |
|
||||
|
if (richtige_antwort[i] == 4) { //vergleichen vov der eingabe zu welche richtige zahl hinter dem passenden index versteckt ist |
||||
printf("Right Answer, well done.\n"); |
printf("Right Answer, well done.\n"); |
||||
return true; |
return true; |
||||
} |
} |
||||
else printf("Wrong answer.\n"); |
|
||||
|
else { |
||||
|
printf("Wrong answer.\n"); //wenn eingabe falsch ist |
||||
|
printf("Would you like to know the right answer?\nInput 1 if you want to see it, 0 if not: "); |
||||
|
scanf_s("%d", &ansehen); |
||||
|
if (ansehen == 1) printf("The right answer was: %d) %s\n", richtige_antwort[i], antworten[4 * i + richtige_antwort[i] - 1]); |
||||
|
else printf("Continuing...\n"); |
||||
|
} |
||||
break; |
break; |
||||
} |
} |
||||
default: { |
|
||||
printf("Wrong Input!"); |
|
||||
|
default: { // eingabe war was anderes als 1,2,3,4 oder 5 |
||||
|
printf("Wrong Input! Going to the next question...\n"); |
||||
return false; |
return false; |
||||
break; |
break; |
||||
} |
} |
||||
} |
} |
||||
return false; |
return false; |
||||
} |
} |
||||
void FzaehlernachAuswahl(bool richtig, int* answeredP, int* correctP) { |
|
||||
if (richtig == true) { |
|
||||
int plus = *answeredP + 1; |
|
||||
*answeredP = plus; |
|
||||
int add = *correctP + 1; |
|
||||
*correctP = add; |
|
||||
|
void fzaehlernachAuswahl(bool richtig, int* answeredP, int* correctP) { |
||||
|
if (richtig == true) { //wenn dei eingabe von vorhin richtig war |
||||
|
*answeredP = *answeredP + 1; //hochzählen von der zählervariablen für beantwortete fragen um 1 |
||||
|
*correctP = *correctP + 1; //hochzählen von der zählervariablen für korrekte antworten um 1 |
||||
} |
} |
||||
else { |
|
||||
int plus = *answeredP + 1; |
|
||||
*answeredP = plus; |
|
||||
|
else { //wenn die eingabe von vorhin falsch war |
||||
|
*answeredP = *answeredP + 1; //hochzählen von der zählervariablen für beantwortete fragen um 1 |
||||
} |
} |
||||
return; |
return; |
||||
} |
} |
||||
|
bool ftryAgain(bool already_played) { |
||||
|
if (already_played == true) { //wenn man das spiel schon gespielt hat |
||||
|
int sure; |
||||
|
printf("Would you like to play again?\n"); |
||||
|
printf("Input 1 to continue gaming, input 0 to close the game: "); |
||||
|
scanf_s("%d", &sure); //eingabe pb man das spiel nochmal spielen möchte |
||||
|
|
||||
|
if (sure == 1) { // nochmal spielen |
||||
|
printf("Starting the program up again..."); |
||||
|
return false; |
||||
|
} |
||||
|
else { //beenden |
||||
|
printf("Input not '1', returning to main menu..."); |
||||
|
return true; |
||||
|
} |
||||
|
} |
||||
|
else { //wenn man das spiel warum auch immer noch nicht gespielt hat |
||||
|
printf("It looks like you havent played the program yet, starting it up..."); |
||||
|
return false; |
||||
|
} |
||||
|
|
||||
|
} |
||||
|
void fabbruch() { |
||||
|
int wirklich; |
||||
|
printf("Do you really want to close the program?\nInput 1 to exit, input 0 to continue gaming: "); |
||||
|
scanf_s("%d", &wirklich); //eingabe ob man denn wirklich das programm beenden möchte |
||||
|
if (wirklich == 1) exit(7); //ende mit code 7 |
||||
|
else return;//frage wird übersprungen, aber programm läuft weiter |
||||
|
} |
Write
Preview
Loading…
Cancel
Save
Reference in new issue