diff --git a/src/main/c/ConvertMode.c b/src/main/c/ConvertMode.c index 61db393..a98dda8 100644 --- a/src/main/c/ConvertMode.c +++ b/src/main/c/ConvertMode.c @@ -12,7 +12,7 @@ double value, result; char Distance[] = { 'mm', 'cm', 'm', 'km', 'feet/inch', 'miles'}; char Weight[] = { 'mg', 'g', 'kg', 't', 'pounds'}; -char Fluid[] = { 'ml', 'l' }; +char Fluid[] = { 'ml', 'l' , 'gallon'}; char Temp[] = { 'celsius', 'fahrenheit' }; char Speed[] = { 'km/h','mp/h' }; char Data[] = { 'B', 'KB', 'MB', 'GB', 'TB', 'PT' }; @@ -128,13 +128,61 @@ double getValue(int choice) { printf("\nThe convertet result is %dlf %d", result, Speed[endingUnit]); break; + case 8://'ml', 'l' + printf("\nEnter what the Unit is starting with (0 ml, 1 l): "); + scanf("%d", &startingUnit); + + printf("\nEnter what the value should it be changed to (0 ml, 1 l): "); + scanf("%d", &endingUnit); + + result = ConLiter(value, startingUnit, endingUnit); + + printf("\nThe convertet result is %dlf %d", result, Fluid[endingUnit]); + break; } } } +/* +double ConSpeed(double speed, int startingUnit, int endingUnit) { + switch (startingUnit) + { + case 0: //kmh to x + switch (endingUnit) + { + case 0: //kmh to kmh + return speed; + break; + + case 1: //kmh to mph + return speed * 0.621371; + break; -double ConLiter() { + default: + break; + } + case 1: //mph to x + switch (endingUnit) + { + case 0: //mph to kmh + return speed * 1.60934; + break; + + case 1: //mph to mph + return speed; + break; + + default: + break; + } + + default: + break; + } } +*/ + + double ConLiterToGallon() { diff --git a/src/main/c/main_taschenrechner.c b/src/main/c/main_taschenrechner.c index cd9d0fe..9ccf8f4 100644 --- a/src/main/c/main_taschenrechner.c +++ b/src/main/c/main_taschenrechner.c @@ -479,6 +479,44 @@ double ConSpeed(double speed, int startingUnit, int endingUnit) { } } +double ConLiter(double liter, int startingUnit, int endingUnit) { + switch (startingUnit) + { + case 0: //ml to x + switch (endingUnit) + { + case 0: //ml to ml + return liter; + break; + + case 1: //ml to l + return liter / 1000; + break; + + default: + break; + } + + case 1: //l to x + switch (endingUnit) + { + case 0: //l to ml + return liter * 1000; + break; + + case 1: //l to l + return liter; + break; + + default: + break; + } + + default: + break; + } +} + //.. // graphMode void graphMode() { diff --git a/src/main/c/taschenrechner.h b/src/main/c/taschenrechner.h index 94164ab..f6ebca0 100644 --- a/src/main/c/taschenrechner.h +++ b/src/main/c/taschenrechner.h @@ -71,4 +71,6 @@ double ConTemp(double temp, int startingUnit, int endingUnit); double ConSpeed(double speed, int startingUnit, int endingUnit); +double ConLiter(double liter, int startingUnit, int endingUnit) + #endif // TASCHENRECHNER_H diff --git a/src/test/c/test_taschenrechner.c b/src/test/c/test_taschenrechner.c index 17fcd4e..002e23c 100644 --- a/src/test/c/test_taschenrechner.c +++ b/src/test/c/test_taschenrechner.c @@ -73,5 +73,11 @@ void test_ConSpeed(void) {//5 kmh to mph TEST_ASSERT_EQUAL(3.10686, result); } +void test_ConLiter(void) {//5 l to ml + double result = ConTemp(5, 1, 0); + TEST_ASSERT_EQUAL(5000, result); +} + + #endif // TEST