diff --git a/src/main/c/ConvertMode.c b/src/main/c/ConvertMode.c index 0cd630e..990c78c 100644 --- a/src/main/c/ConvertMode.c +++ b/src/main/c/ConvertMode.c @@ -164,6 +164,18 @@ double getValue(int choice) { printf("\nThe convertet result is %dlf %d", result, Data[endingUnit]); break; + + case 11://char Distance[] = { 'mm', 'cm', 'm', 'km', 'feet/inch', 'miles'}; + printf("\nEnter what the Unit is starting with (0 mm, 1 cm, 2 m , 3 km,): "); + scanf("%d", &startingUnit); + + printf("\nEnter what the value should it be changed to (0 mm, 1 cm, 2 m , 3 km,): "); + scanf("%d", &endingUnit); + + result = ConArea(value, startingUnit, endingUnit); + + printf("\nThe convertet result is %dlf %dē", result, Distance[endingUnit]); + break; } } } @@ -208,14 +220,6 @@ double ConSpeed(double speed, int startingUnit, int endingUnit) { */ - - - - -double ConArea() { - -} - double ConVolume() { } diff --git a/src/main/c/main_taschenrechner.c b/src/main/c/main_taschenrechner.c index 1b185b6..fa4d493 100644 --- a/src/main/c/main_taschenrechner.c +++ b/src/main/c/main_taschenrechner.c @@ -189,6 +189,106 @@ double ConMeter(double meter, int startingUnit, int endingUnit) { } } +double ConArea(double area, int startingUnit, int endingUnit) { + switch (startingUnit) + { + case 0: //mm to x + switch (endingUnit) + { + case 0: //1mm + return area; + break; + + case 1: //0.01cm + return area / 100; + break; + + case 2: //0.000001m + return area / 1000000; + break; + + case 3: //0.000000000001km + return area / 1000000000000; + break; + + default: + break; + } + + case 1: //cm to x + switch (endingUnit) + { + case 0: //100 + return area * 100; + break; + + case 1: //1 + return area; + break; + + case 2: //0.0001 + return area / 10000; + break; + + case 3: //0.0000000001 + return area / 10000000000; + break; + + default: + break; + } + + case 2: //m to x + switch (endingUnit) + { + case 0: //1000000 + return area * 1000000; + break; + + case 1: //10000 + return area * 10000; + break; + + case 2: //1 + return area; + break; + + case 3: //0.000001 + return area / 1000000; + break; + + default: + break; + } + + case 3:// km to x + switch (endingUnit) + { + case 0: // 1000000000000 + return area * 1000000000000; + break; + + case 1: // 10000000000 + return area * 10000000000; + break; + + case 2: // 1000000 m + return area * 1000000; + break; + + case 3: //1 km + return area; + break; + + default: + break; + } + + default: + break; + } +} + double ConMeterToFoot(double distance, int startingUnit, int endingUnit) { switch (startingUnit) { diff --git a/src/main/c/taschenrechner.h b/src/main/c/taschenrechner.h index 720edc6..c24090b 100644 --- a/src/main/c/taschenrechner.h +++ b/src/main/c/taschenrechner.h @@ -77,4 +77,6 @@ double ConLiterToGallon(double fluid, int startingUnit, int endingUnit); double ConData(double data, int startingUnit, int endingUnit); +double ConArea(double area, int startingUnit, int endingUnit); + #endif // TASCHENRECHNER_H diff --git a/src/test/c/test_taschenrechner.c b/src/test/c/test_taschenrechner.c index 4265c0d..6adeb59 100644 --- a/src/test/c/test_taschenrechner.c +++ b/src/test/c/test_taschenrechner.c @@ -88,5 +88,10 @@ void test_ConData(void) {//5 b to kb TEST_ASSERT_EQUAL(0.005, result); } +void test_ConArea(void) {//5 mm to cm + double result = ConData(5, 0, 1); + TEST_ASSERT_EQUAL(0.0005), result); +} + #endif // TEST