Browse Source
Merge branch 'Christian' into 'main'
Merge branch 'Christian' into 'main'
Christian erster Merge See merge request fdai7760/the-quizstars!4main
fdai7474
11 months ago
3 changed files with 148 additions and 0 deletions
-
97src/wwm.c
-
11src/wwm.h
-
40test/test_wwm.c
@ -0,0 +1,97 @@ |
|||
#include <time.h> |
|||
#include <stdio.h> |
|||
#include <stdlib.h> |
|||
#include "wwm.h" |
|||
|
|||
int runde = 0; |
|||
int geld = 0; |
|||
int frage = 0; |
|||
int useranswer; |
|||
int test; |
|||
|
|||
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; |
|||
} |
|||
|
|||
|
|||
int crandomNumber() { |
|||
srand(time(NULL)); |
|||
frage = rand() % 10; |
|||
return frage; |
|||
|
|||
} |
|||
|
|||
|
|||
|
|||
void wwm(){ |
|||
|
|||
printf("Welcome to ´Who wants to be a millionaire?´ \n"); |
|||
|
|||
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?", |
|||
"In which country would you find the Great Wall?", |
|||
"How many meters are in a kilometer?", |
|||
"How many colors are there in a rainbow?", |
|||
"What is the square root of 25?", |
|||
"Who painted the Mona Lisa?", |
|||
"What is the largest ocean on earth?", |
|||
"What is the largest planet in our solar system?" |
|||
}; |
|||
|
|||
const char* answers[][4] = { |
|||
{"Mars", "Venus", "Earth", "Jupiter"}, |
|||
{"Munich", "Berlin", "Cologne", "Frankfurt am Main"}, |
|||
{"Antarctica", "Sahara", "Gobi", "Arctica" }, |
|||
{"USA", "China", "Russia", "Japan"}, |
|||
{"100", "10", "1", "1000"}, |
|||
{"6", "7", "8", "9"}, |
|||
{"5", "25", "20", "10"}, |
|||
{"Vincent van Gogh", "Pablo Picasso", "Leonardo da Vinci", "Michelangelo"}, |
|||
{"Pacific Ocean", "Atlantic Ocean", "Arctic Ocean", "Indian Ocean"}, |
|||
{"Merkur", "Jupiter", "Neptun", "Pluto"} |
|||
}; |
|||
|
|||
int correctAnswer[] = { |
|||
3, 2, 1, 2, 4 |
|||
}; |
|||
|
|||
|
|||
for (int r = 1; r <= 16; r++){ |
|||
if (r == 16) { |
|||
printf("Congratulations ! You have won 1.000.000 $"); |
|||
return; |
|||
} |
|||
|
|||
|
|||
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]); |
|||
|
|||
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!\n"); |
|||
runde++; |
|||
setGeld(runde); |
|||
} |
|||
else { |
|||
printf("What a shame! That is wrong!\n You lost %d $", geld); |
|||
} |
|||
} |
|||
|
|||
return; |
|||
|
|||
} |
|||
} |
@ -1,6 +1,17 @@ |
|||
#ifndef WWM_H |
|||
#define WWM_H |
|||
|
|||
extern int runde; |
|||
extern int geld; |
|||
extern int frage; |
|||
extern int useranswer; |
|||
|
|||
extern int Geldstufen[]; |
|||
|
|||
int crandomNumber(); |
|||
|
|||
int setGeld(int runde); |
|||
|
|||
void wwm(); |
|||
|
|||
#endif // ende WWM_H |
@ -0,0 +1,40 @@ |
|||
// test_wwm.c |
|||
|
|||
#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 |
|||
runde = 0; |
|||
geld = 0; |
|||
frage = 0; |
|||
useranswer = 0; |
|||
|
|||
// Call setGeld and check the initial values |
|||
TEST_ASSERT_EQUAL(100, setGeld(1)); |
|||
TEST_ASSERT_EQUAL(100, geld); |
|||
|
|||
} |
|||
|
|||
void test_setGeld_2(void) { |
|||
|
|||
runde = 0; |
|||
|
|||
TEST_ASSERT_EQUAL(300, setGeld(3)); |
|||
|
|||
|
|||
} |
|||
|
|||
void test_crandomNumber(void){ |
|||
int result = crandomNumber(); |
|||
TEST_ASSERT_TRUE(result >= 0 && result <= 9); |
|||
|
|||
} |
Write
Preview
Loading…
Cancel
Save
Reference in new issue