Browse Source

Merge branch 'Christian' into 'main'

Christian 2ter merge

See merge request fdai7760/the-quizstars!11
main
fdai7474 11 months ago
parent
commit
b6ed68cb99
  1. 200
      src/wwm.c
  2. 2
      src/wwm.h
  3. 7
      test/test_wwm.c

200
src/wwm.c

@ -3,19 +3,23 @@
#include <stdlib.h>
#include "wwm.h"
// Deklaration aller Variablen
int runde = 0;
int geld = 0;
int frage = 0;
int useranswer;
int test;
int ceingabe();
// setzt Geldbetrag auf entsprechenden Wert
int setGeld(int runde){
int Geldstufen[] = {0, 100, 200, 300, 500, 1000, 2000, 4000, 8000, 16000, 32000, 64000, 125000, 250000, 500000, 1000000};
geld = Geldstufen[runde];
return geld;
}
// Berechnet zufällige Nummer für die Frage aus
int crandomNumber() {
srand(time(NULL));
frage = rand() % 10;
@ -23,13 +27,44 @@ int crandomNumber() {
}
// Überprüft Antwort auf 5 und Zahlen kleiner als 1 oder größer als 4
void ccheckAnswer(int useranswer) {
if (useranswer == 5) {
printf("That is a shame, but ok.\n");
printf("Congratulations! You have won %d $!", geld);
exit(0);
}
if (useranswer < 1 || useranswer > 4) {
printf("Please enter a number beetween 1 and 4 or enter 5 to end the game!\n");
ceingabe();
}
}
// Eingabe mit Pürfung auf integer
int ceingabe() {
printf("Your answer (1-4):");
int result = scanf("%d", &useranswer);
if (result == 0) {
printf("Please enter a number beetween 1 and 4 to answer or 5 to end the game!\n");
while (getchar() != '\n')
return ceingabe();
}
ccheckAnswer(useranswer);
return useranswer;
}
void wwm(){
printf("Welcome to ´Who wants to be a millionaire?´ \n");
printf("Welcome to Who wants to be a millionaire? \n");
printf("Choose your answer with the numbers 1-4! \n");
printf("If you want to stop and take the money, type in 5!\n");
const char* question[] = {
//Array Fragen
// easy fragen: trivia www.buzzfeed.com/laurafrustaci/easy-trivia-questions
// medium und hard fragen: www.opinionstage.com/blog/trivia-questions/
const char* question_easy[] = {
"Which planet is known as the `blue planet`?",
"What is the capital of Germany?",
"What is the largest desert in the world?",
@ -42,7 +77,7 @@ void wwm(){
"What is the largest planet in our solar system?"
};
const char* answers[][4] = {
const char* answers_easy[][4] = {
{"Mars", "Venus", "Earth", "Jupiter"},
{"Munich", "Berlin", "Cologne", "Frankfurt am Main"},
{"Antarctica", "Sahara", "Gobi", "Arctica" },
@ -55,43 +90,148 @@ void wwm(){
{"Merkur", "Jupiter", "Neptun", "Pluto"}
};
int correctAnswer[] = {
3, 2, 1, 2, 4
int correctAnswer_easy[] = {
3, 2, 1, 2, 4, 2, 1, 3, 1, 2
};
for (int r = 1; r <= 16; r++){
if (r == 16) {
printf("Congratulations ! You have won 1.000.000 $");
return;
}
const char* questions_medium[] = {
"In what year did the Berlin Wall fall?",
"What is the capital city of Brazil?",
"Who is known as the Father of Modern Physics?",
"What is the largest island in the world?",
"What is the chemical symbol for silver?",
"What is the largest bone in the human body?",
"In which year did the Titanic sink?",
"What is the capital city of Argentina?",
"In which year did World War II end?",
"What is the currency of Japan?"
};
const char* answers_medium[][4] = {
{"1989", "1998", "1994", "1990"},
{"Buenos Aires", "Sao Paulo", "Brasilia", "Rio de Janeiro"},
{"Thomas Edison", "Marie Curie", "Isaac Newton", "Albert Einstein"},
{"Australia", "Greenland", "Madascar", "Borneo"},
{"Au", "Ag", "Su", "Si"},
{"Femur", "Sternum", "tibia", "fibula"},
{"1910", "1915", "1912", "1920"},
{"Brasilia", "La Plata", "Rosario", "Buenos Aires"},
{"1945", "1940", "1948", "1933"},
{"Yuan", "Yen", "Rupiah", "Rupee"}
};
printf("__________________________________________________ \n\n");
printf("You are at stage %d and have %d $\n", runde, geld);
srand(time(0));
crandomNumber();
printf("Question %d: %s\n", runde + 1, question[frage]);
int correctAnswer_medium[] = {
1, 3, 4, 2, 2, 1, 3, 4, 1, 2
};
for (int i = 0; i < 4; i++) {
printf("%d. %s \n", i + 1, answers[frage][i]);
const char* questions_hard[] = {
"What is the rarest blood type among humans?",
"In which year did Serena Williams win her first Grand Slam singles title?",
"In what year and in which city were the first modern Olympic Games held?",
"Benjamin Franklin was a key figure in the drafting of the United States Constitution. Which state did he represent during the Constitutional Convention in 1787?",
"What is the capital city of Bhutan?",
"What is the capital city of Bhutan?",
"In mathematics, what is the name for a number that is not a prime number and has more than two factors?",
"Who is the Greek god of war and son of Zeus and Hera?",
"What is the chemical symbol for the element mercury?",
"What is the name of the largest moon of Jupiter?",
"Where did backgammon originate?"
};
int useranswer;
printf("Your answer (1-4):");
scanf("%d", &useranswer);
const char* answers_hard[][4] = {
{"A", "B", "0", "AB"},
{"1999", "1995", "2000", "2002"},
{"1894 in Rome, Italy", "1896 in Athens, Greece", "1898 in Madrid, Spain", "1890 in Istanbul, Turkey"},
{"Pennsylvania", "Oregon", "Texas", "Florida"},
{"Paro", "Punakha", "Thimphu", "Tongsa"},
{"prime number", "composite number", "fibonacci numbers", "perfect numbers"},
{"Herkules", "Hermes", "Ares", "Loki"},
{"Hg", "Ha", "Me", "My"},
{"Europa", "Titan", "Ganymede", "Io"},
{"Roman Empire", "Persia", "Greece", "Inka"}
};
int correctAnswer_hard[] = {
4, 1, 2, 1, 3, 2, 3, 1, 3, 2
};
if (useranswer == correctAnswer[frage]) {
printf("That is correct!\n");
runde++;
setGeld(runde);
for (int r = 1; r <= 16; r++){
if (r == 16) {
printf("Congratulations ! You have won 1.000.000 $");
return;
}
else {
printf("What a shame! That is wrong!\n You lost %d $", geld);
// If für Runde 1-5
if (r <= 5) {
printf("__________________________________________________ \n\n");
printf("You are at stage %d and have %d $\n", runde, geld);
crandomNumber(); //Berechnung welcher Frage
printf("Question %d: %s\n", runde + 1, question_easy[frage]); //Frage Ausgabe
for (int i = 0; i < 4; i++) {
printf("%d. %s \n", i + 1, answers_easy[frage][i]);
} // Antwortenb Ausgabe
ceingabe(); // Eingabe Antwort, automatische Eingabeprüfung auf Zahlen 1-4
// Prüfung auf korrekte Antwort
// korrekte Antwort
if (useranswer == correctAnswer_easy[frage]) {
printf("That is correct!\n");
runde++;
setGeld(runde);
}
// falsche Antwort
else {
printf("That is a shame! That is wrong!\n You lost %d $", geld);
return;
}
}
}
return;
if (r > 5 && r <= 10) {
printf("___________________________________________________________\n\n");
printf("You are at stage %d and have %d $\n", runde + 1, geld);
crandomNumber();
printf("Question %d: %s\n", runde + 1, questions_medium[frage]);
for (int i = 0; i < 4; i++) {
printf("%d. %s \n", i + 1, answers_medium[frage][i]);
};
ceingabe();
if (useranswer == correctAnswer_medium[frage]) {
printf("That is correct!\n");
runde++;
setGeld(runde);
}
else {
printf("What a shame! That is wrong! \n You lost %d $ ", geld);
break;
}
}
if (r > 10 && r <= 15) {
printf("___________________________________________________________\n\n");
printf("You are at stage %d and have %d $\n", runde + 1, geld);
crandomNumber();
printf("Question %d: %s\n", runde + 1, questions_hard[frage]);
for (int i = 0; i < 4; i++) {
printf("%d. %s \n", i + 1, answers_hard[frage][i]);
};
ceingabe();
if (useranswer == correctAnswer_hard[frage]) {
printf("That is correct!\n");
runde++;
setGeld(runde);
}
else {
printf("What a shame! That is wrong! \n You lost %d $ ", geld);
break;
}
}
}
}

2
src/wwm.h

@ -9,6 +9,8 @@ extern int useranswer;
extern int Geldstufen[];
int crandomNumber();
int ceingabe();
void ccheckAnswer(int useranswer);
int setGeld(int runde);

7
test/test_wwm.c

@ -3,13 +3,7 @@
#include "unity.h"
#include "wwm.h"
void setUp(void) {
// set up any initializations if needed
}
void tearDown(void) {
// clean up after the test if needed
}
void test_setGeld_1(void) {
// Initialize or reset variables if needed
@ -38,3 +32,4 @@ void test_crandomNumber(void){
TEST_ASSERT_TRUE(result >= 0 && result <= 9);
}
Loading…
Cancel
Save