diff --git a/src/minirechner.c b/src/minirechner.c index 37fa823..6a133f3 100644 --- a/src/minirechner.c +++ b/src/minirechner.c @@ -14,4 +14,15 @@ float subtrahieren(float a, float b) { //multiplizieren float multiplizieren(float a, float b) { return a * b; +} + +//dividieren +float dividieren(float a, float b) { + if (b == 0) { + printf("Bitte nicht durch 0 dividieren\n"); + return 0; + } + else { + return a / b; + } } \ No newline at end of file diff --git a/src/minirechner.h b/src/minirechner.h index 569a7b7..8c4466f 100644 --- a/src/minirechner.h +++ b/src/minirechner.h @@ -4,5 +4,6 @@ float addieren(float a, float b); float subtrahieren(float a, float b); float multiplizieren(float a, float b); +float dividieren(float a, float b); #endif // MINIRECHNER_H diff --git a/test/test_minirechner.c b/test/test_minirechner.c index a3cf7b2..008e592 100644 --- a/test/test_minirechner.c +++ b/test/test_minirechner.c @@ -81,4 +81,11 @@ void test_minitaschenrechner_0_mal_5(void) TEST_ASSERT_EQUAL(0, result); } +// test dividieren +void test_minitaschenrechner_9_durch_3(void) +{ + float result = dividieren(9, 3); + TEST_ASSERT_EQUAL(3, result); +} + #endif // TEST