From 318e68a75e9f82e1a72541b2f86c59cd7daa4bc5 Mon Sep 17 00:00:00 2001 From: Christian Reum Date: Mon, 5 Feb 2024 18:20:05 +0100 Subject: [PATCH] =?UTF-8?q?functional=209:=20for-Schleife=20f=C3=BCr=2015?= =?UTF-8?q?=20Fragen?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/wwm.c | 45 +++++++++++++++++++++++++-------------------- 1 file changed, 25 insertions(+), 20 deletions(-) diff --git a/src/wwm.c b/src/wwm.c index 31c819a..0d1d61d 100644 --- a/src/wwm.c +++ b/src/wwm.c @@ -5,6 +5,7 @@ int runde = 0; int geld = 0; +int frage = 0; void wwm(){ printf("Welcome to ´Who wants to be a millionaire?´ \n"); @@ -13,42 +14,46 @@ void wwm(){ const char* question[] = { "Which planet is known as the `blue planet`?", "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] = { {"Mars", "Venus", "Earth", "Jupiter"}, {"Munich", "Berlin", "Cologne", "Frankfurt am Main"}, - {"Antarctica", "Sahara", "Gobi", "Arctica" } + {"Antarctica", "Sahara", "Gobi", "Arctica" }, + {"USA", "China", "Russia", "Japan"}, + {"100", "10", "1", "1000"} }; 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; }