From 77a2938724673e28b3d00714b3e10399737421a2 Mon Sep 17 00:00:00 2001 From: Enrico Schellenberger Date: Mon, 5 Feb 2024 19:22:55 +0100 Subject: [PATCH] fixed error with case 2 and 3 that wrong unit is shown --- src/main/c/ConvertMode.c | 35 +++++++++++++++++++++++++++++++++-- 1 file changed, 33 insertions(+), 2 deletions(-) diff --git a/src/main/c/ConvertMode.c b/src/main/c/ConvertMode.c index e636254..4b8333d 100644 --- a/src/main/c/ConvertMode.c +++ b/src/main/c/ConvertMode.c @@ -10,7 +10,7 @@ int choice, startingUnit, endingUnit; double value, result; -char Distance[] = { 'mm', 'cm', 'm', 'km' }; +char Distance[] = { 'mm', 'cm', 'm', 'km', 'feet/inch', 'miles'}; char Weight[] = { 'mg', 'g', 'kg', 't' }; char Fluid[] = { 'ml', 'l' }; char Data[] = { 'B', 'KB', 'MB', 'GB', 'TB', 'PT' }; @@ -45,6 +45,15 @@ double getValue(int choice) { scanf("%d", &endingUnit); result = ConMeterToFoot(value, startingUnit, endingUnit); + + if (endingUnit == 0) { //if feet/inch change to 4. in array of Distance + endingUnit = 4; + } + + else if (endingUnit == 1) { //if meter change to 2. in array of Distance + endingUnit = 2; + } + printf("\nThe convertet result is %dlf %d", result, Distance[endingUnit]); break; @@ -58,10 +67,32 @@ double getValue(int choice) { result = ConKilometerToMiles(value, startingUnit, endingUnit); + if (endingUnit == 0) { //if miles change to 5. in array of Distance + endingUnit = 5; + } + + else if (endingUnit == 1) { //if kilometer change to 2. in array of Distance + endingUnit = 3; + } + printf("\nThe convertet result is %dlf %d", result, Distance[endingUnit]); break; } + + case 4://'mg', 'g', 'kg', 't' + printf("\nEnter what the Unit is starting with (0 mg, 1 g, 2 kg , 3 t): "); + scanf("%d", &startingUnit); + + printf("\nEnter what the value should it be changed to (0 mg, 1 g, 2 kg , 3 t): "); + scanf("%d", &endingUnit); + + result = ConKilometerToMiles(value, startingUnit, endingUnit); + + printf("\nThe convertet result is %dlf %d", result, Distance[endingUnit]); + break; + + } } } @@ -203,7 +234,7 @@ double ConMeterToFoot(double distance, int startingUnit, int endingUnit) { } } -double ConKilometerToMiles() { +double ConKilometerToMiles(double distance, int startingUnit, int endingUnit) { switch (startingUnit) { case 0: //miles to x