diff --git a/src/main/c/ConvertMode.c b/src/main/c/ConvertMode.c index 1481d29..0cd630e 100644 --- a/src/main/c/ConvertMode.c +++ b/src/main/c/ConvertMode.c @@ -153,7 +153,17 @@ double getValue(int choice) { printf("\nThe convertet result is %dlf %d", result, Fluid[endingUnit]); break; + case 10://char Data[] = { 'B', 'KB', 'MB', 'GB', 'TB', 'PT' }; + printf("\nEnter what the Unit is starting with (0 B, 1 KB, 2 MB , 3 GB, 4 TB, 5 PT): "); + scanf("%d", &startingUnit); + + printf("\nEnter what the value should it be changed to (0 B, 1 KB, 2 MB , 3 GB, 4 TB, 5 PT): "); + scanf("%d", &endingUnit); + + result = ConData(value, startingUnit, endingUnit); + printf("\nThe convertet result is %dlf %d", result, Data[endingUnit]); + break; } } } @@ -201,9 +211,6 @@ double ConSpeed(double speed, int startingUnit, int endingUnit) { -double ConData() { - -} double ConArea() { diff --git a/src/main/c/main_taschenrechner.c b/src/main/c/main_taschenrechner.c index 1bdf9cd..1b185b6 100644 --- a/src/main/c/main_taschenrechner.c +++ b/src/main/c/main_taschenrechner.c @@ -555,6 +555,201 @@ double ConLiterToGallon(double fluid, int startingUnit, int endingUnit) { } } +double ConData(double data, int startingUnit, int endingUnit) { + switch (startingUnit) + {//'B', 'KB', 'MB', 'GB', 'TB', 'PT' + case 0: //B to x + switch (endingUnit) + { + case 0: //1 + return data; + break; + + case 1: //0.001 + return data / 1000; + break; + + case 2: //0.000001 + return data / 1000000; + break; + + case 3: //0.000000001 + return data / 1000000000; + break; + + case 4: //0.000000000001 + return data / 1000000000000; + break; + + case 5: //0.000000000000001 + return data / 1000000000000000; + break; + + default: + break; + } + + case 1: //KB to x + switch (endingUnit) + { + case 0: //1000 + return data * 1000; + break; + + case 1: //1 + return data; + break; + + case 2: //0.001 + return data / 1000; + break; + + case 3: //0.000001 + return data / 1000000; + break; + + case 4: //0.000000001 + return data / 1000000000; + break; + + case 5: //0.000000000001 + return data / 1000000000000; + break; + + default: + break; + } + + case 2: //MB to x + switch (endingUnit) + { + case 0: //0.000001 + return data * 1000000; + break; + + case 1: //0.001 + return data * 1000; + break; + + case 2: //1 + return data; + break; + + case 3: //0.001 + return data / 1000; + break; + + case 4: //0.000001 + return data / 1000000; + break; + + case 5: //0.000000001 + return data / 1000000000; + break; + + default: + break; + } + + + case 3: //GB to x + switch (endingUnit) + { + case 0: //0.000000001 + return data * 1000000000; + break; + + case 1: //0.000001 + return data * 1000000; + break; + + case 2: //1000 + return data * 1000;; + break; + + case 3: //1 + return data; + break; + + case 4: //0.001 + return data / 1000; + break; + + case 5: //0.000001 + return data / 1000000; + break; + + default: + break; + } + + + case 4: //TB to x + switch (endingUnit) + { + case 0: //0.000000000001 + return data * 1000000000000; + break; + + case 1: //0.000000001 + return data * 1000000000; + break; + + case 2: //1000000 + return data * 1000000;; + break; + + case 3: //1000 + return data * 1000; + break; + + case 4: //1 + return; + break; + + case 5: //0.001 + return data / 1000; + break; + + default: + break; + } + + + case 5: //PB to x + switch (endingUnit) + { + case 0: //0.000000000000001 + return data * 1000000000000000; + break; + + case 1: //0.000000000001 + return data * 1000000000000; + break; + + case 2: //1000000000 + return data * 1000000000;; + break; + + case 3: //1000000 + return data * 1000000; + break; + + case 4: //1000 + return data * 1000; + break; + + case 5: //1 + return data; + break; + + default: + break; + } + } +} + + //.. // graphMode void graphMode() { diff --git a/src/main/c/taschenrechner.h b/src/main/c/taschenrechner.h index 97846a5..720edc6 100644 --- a/src/main/c/taschenrechner.h +++ b/src/main/c/taschenrechner.h @@ -75,4 +75,6 @@ double ConLiter(double liter, int startingUnit, int endingUnit); double ConLiterToGallon(double fluid, int startingUnit, int endingUnit); +double ConData(double data, int startingUnit, int endingUnit); + #endif // TASCHENRECHNER_H diff --git a/src/test/c/test_taschenrechner.c b/src/test/c/test_taschenrechner.c index c1008b2..4265c0d 100644 --- a/src/test/c/test_taschenrechner.c +++ b/src/test/c/test_taschenrechner.c @@ -83,5 +83,10 @@ void test_ConLiterToGallon(void) {//5 l to gallon TEST_ASSERT_EQUAL(1.32086, result); } +void test_ConData(void) {//5 b to kb + double result = ConData(5, 0, 1); + TEST_ASSERT_EQUAL(0.005, result); +} + #endif // TEST