|
@ -0,0 +1,92 @@ |
|
|
|
|
|
#include <stdio.h> |
|
|
|
|
|
#include <string.h> |
|
|
|
|
|
|
|
|
|
|
|
typedef struct |
|
|
|
|
|
{ |
|
|
|
|
|
const char* question; |
|
|
|
|
|
char answer[256]; |
|
|
|
|
|
}Question; |
|
|
|
|
|
|
|
|
|
|
|
typedef struct |
|
|
|
|
|
{ |
|
|
|
|
|
int size; |
|
|
|
|
|
Question questions[12]; |
|
|
|
|
|
}Level; |
|
|
|
|
|
|
|
|
|
|
|
typedef struct |
|
|
|
|
|
{ |
|
|
|
|
|
int size; |
|
|
|
|
|
const char* name; |
|
|
|
|
|
Level lvlQuestions[10]; |
|
|
|
|
|
}Category; |
|
|
|
|
|
|
|
|
|
|
|
int main() |
|
|
|
|
|
{ |
|
|
|
|
|
int score = 0; |
|
|
|
|
|
int level = 0; |
|
|
|
|
|
int maxLvl = 2; // definiert die Anzahl an Leveln |
|
|
|
|
|
|
|
|
|
|
|
char input[256]; |
|
|
|
|
|
|
|
|
|
|
|
Question fussQst1 = {.question = "Welche Fussballmannschaft wurde 1930 Weltmeister?", .answer = "Uruguay"}; |
|
|
|
|
|
Question fussQst2 = {.question = "Welche Fussballmannschaft wurde 1934 Weltmeister?", .answer = "Italien"}; |
|
|
|
|
|
Question fussQst3 = {.question = "Welche Fussballmannschaft wurde 1938 Weltmeister?", .answer = "Italien"}; |
|
|
|
|
|
Level fussLevel1 = {.questions = {fussQst1, fussQst2, fussQst3}, .size = 3}; // size = anzahl an Fragen |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Category fussball = {.size = 2, .name = "Fussball", .lvlQuestions = {fussLevel1, }}; // size = anzahl an leveln in Kategorie |
|
|
|
|
|
|
|
|
|
|
|
Category categories[4] = |
|
|
|
|
|
{ |
|
|
|
|
|
fussball, |
|
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
printf("Willkommen beim Quiz-Spiel! Beantworten Sie die folgenden Fragen:\n"); |
|
|
|
|
|
|
|
|
|
|
|
int questCount = 0; |
|
|
|
|
|
int curCatNum = 0; |
|
|
|
|
|
int catCount = 1; // anzahl an kategorien |
|
|
|
|
|
|
|
|
|
|
|
for (int i = 0; i < catCount; i++) |
|
|
|
|
|
{ |
|
|
|
|
|
Level lvlQuestions[10]; |
|
|
|
|
|
memcpy(lvlQuestions, categories[i].lvlQuestions, sizeof(categories[i].lvlQuestions)); |
|
|
|
|
|
|
|
|
|
|
|
printf("Kategorie %s\n", categories[i].name); |
|
|
|
|
|
|
|
|
|
|
|
while (level < sizeof(lvlQuestions) / sizeof(Level)) |
|
|
|
|
|
{ |
|
|
|
|
|
for (int i = 0; i < lvlQuestions[level].size; i++) |
|
|
|
|
|
{ |
|
|
|
|
|
printf(lvlQuestions[level].questions[i].question); |
|
|
|
|
|
printf(" "); |
|
|
|
|
|
fgets(input, 256, stdin); |
|
|
|
|
|
input[strlen(input) - 1] = '\0'; |
|
|
|
|
|
const char* buf = lvlQuestions[level].questions[i].answer; |
|
|
|
|
|
if (strcmp(input, buf)) |
|
|
|
|
|
{ |
|
|
|
|
|
printf("Falsch. Die richtige Antwort ist: %s.\n", lvlQuestions[level].questions[i].answer); |
|
|
|
|
|
} |
|
|
|
|
|
else |
|
|
|
|
|
{ |
|
|
|
|
|
printf("Richtig!\n"); |
|
|
|
|
|
score++; |
|
|
|
|
|
} |
|
|
|
|
|
memset(&input[0], 0, sizeof(input)); |
|
|
|
|
|
|
|
|
|
|
|
questCount++; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
printf("Level %d abgeschlossen!\n", level + 1); |
|
|
|
|
|
level++; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
level = 0; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// Ergebnis |
|
|
|
|
|
printf("Sie haben %d von %d Fragen richtig beantwortet.\n", score, questCount); |
|
|
|
|
|
|
|
|
|
|
|
return 0; |
|
|
|
|
|
} |