Browse Source

functional 9: for-Schleife für 15 Fragen

remotes/origin/Christian
Christian Reum 11 months ago
parent
commit
318e68a75e
  1. 45
      src/wwm.c

45
src/wwm.c

@ -5,6 +5,7 @@
int runde = 0; int runde = 0;
int geld = 0; int geld = 0;
int frage = 0;
void wwm(){ void wwm(){
printf("Welcome to ´Who wants to be a millionaire?´ \n"); printf("Welcome to ´Who wants to be a millionaire?´ \n");
@ -13,42 +14,46 @@ void wwm(){
const char* question[] = { const char* question[] = {
"Which planet is known as the `blue planet`?", "Which planet is known as the `blue planet`?",
"What is the capital of Germany?", "What is the capital of Germany?",
"What is the largest desert in the world?"
"What is the largest desert in the world?",
"In which country would you find the Great Wall?",
"How many meters are in a kilometer?"
}; };
const char* answers[][4] = { const char* answers[][4] = {
{"Mars", "Venus", "Earth", "Jupiter"}, {"Mars", "Venus", "Earth", "Jupiter"},
{"Munich", "Berlin", "Cologne", "Frankfurt am Main"}, {"Munich", "Berlin", "Cologne", "Frankfurt am Main"},
{"Antarctica", "Sahara", "Gobi", "Arctica" }
{"Antarctica", "Sahara", "Gobi", "Arctica" },
{"USA", "China", "Russia", "Japan"},
{"100", "10", "1", "1000"}
}; };
int correctAnswer[] = { int correctAnswer[] = {
3, 2, 1
3, 2, 1, 2, 4
}; };
srand(time(0));
int frage = rand() % 5;
for (r = 1; r <= 15; r++){
srand(time(0));
int frage = rand() % 5;
printf("Question %d: %s\n", runde + 1, question[frage]);
for (int i = 0; i < 4; i++) {
printf("%d. %s \n", i + 1, answers[frage][i]);
printf("Question %d: %s\n", runde + 1, question[frage]);
int useranswer;
printf("Your answer (1-4):");
scanf("%d", &useranswer);
for (int i = 0; i < 4; i++) {
printf("%d. %s \n", i + 1, answers[frage][i]);
int useranswer;
printf("Your answer (1-4):");
scanf("%d", &useranswer);
if (useranswer == correctAnswer[frage]) {
printf("That is correct!");
}
else {
printf("That is wrong!");
if (useranswer == correctAnswer[frage]) {
printf("That is correct!");
runde++;
}
else {
printf("That is wrong!");
}
} }
return;
return;
} }
Loading…
Cancel
Save