From 7ad539f78d9a2597c452664d0f1e59442ca148c2 Mon Sep 17 00:00:00 2001 From: Enrico Schellenberger Date: Mon, 5 Feb 2024 18:52:40 +0100 Subject: [PATCH 1/5] added ConMeterToFeet logic to ConvertMode.c --- src/main/c/ConvertMode.c | 50 ++++++++++++++++++++++++++++++++++++++-- 1 file changed, 48 insertions(+), 2 deletions(-) diff --git a/src/main/c/ConvertMode.c b/src/main/c/ConvertMode.c index 2d9e9ae..874c333 100644 --- a/src/main/c/ConvertMode.c +++ b/src/main/c/ConvertMode.c @@ -37,6 +37,18 @@ double getValue(int choice) { printf("\nThe convertet result is %dlf %d", result, Distance[endingUnit]); break; + case 2: + printf("\nEnter what the Unit is starting with (0 feet/Inch, 1 meter): "); + scanf("%d", &startingUnit); + + printf("\nEnter what the value should it be changed to (0 feet/Inch, 1 meter): "); + scanf("%d", &endingUnit); + + result = ConMeterToFoot(value, startingUnit, endingUnit); + + printf("\nThe convertet result is %dlf %d", result, Distance[endingUnit]); + break; + } } } @@ -141,8 +153,42 @@ double ConMeter(double meter, int startingUnit, int endingUnit) { } } -double ConMeterToFoot() { - +double ConMeterToFoot(double distance, int startingUnit, int endingUnit) { + switch (startingUnit) + { + case 0: //feet/inch to x + switch (endingUnit) + { + case 0: //feet/inch to feet/inch + return distance; + break; + + case 1: //feet/inch to meter + return distance / 3,28084; + break; + + default: + break; + } + + case 1: //meter to x + switch (endingUnit) + { + case 0: //meter to feet/inch + return distance * 3, 28084; + break; + + case 1: //feet/inch to feet/inch + return distance; + break; + + default: + break; + } + + default: + break; + } } double ConKilometerToMiles() { From 104b8fa4d17a3b4117ee099e25fe0874871926b4 Mon Sep 17 00:00:00 2001 From: Enrico Schellenberger Date: Mon, 5 Feb 2024 19:04:30 +0100 Subject: [PATCH 2/5] added logic to ConKilometerToMiles --- src/main/c/ConvertMode.c | 48 +++++++++++++++++++++++++++++++++++++++- 1 file changed, 47 insertions(+), 1 deletion(-) diff --git a/src/main/c/ConvertMode.c b/src/main/c/ConvertMode.c index 874c333..e636254 100644 --- a/src/main/c/ConvertMode.c +++ b/src/main/c/ConvertMode.c @@ -49,6 +49,18 @@ double getValue(int choice) { printf("\nThe convertet result is %dlf %d", result, Distance[endingUnit]); break; + case 3: + printf("\nEnter what the Unit is starting with (0 miles, 1 kilometer): "); + scanf("%d", &startingUnit); + + printf("\nEnter what the value should it be changed to (0 miles, 1 kilometer): "); + scanf("%d", &endingUnit); + + result = ConKilometerToMiles(value, startingUnit, endingUnit); + + printf("\nThe convertet result is %dlf %d", result, Distance[endingUnit]); + break; + } } } @@ -192,7 +204,41 @@ double ConMeterToFoot(double distance, int startingUnit, int endingUnit) { } double ConKilometerToMiles() { - + switch (startingUnit) + { + case 0: //miles to x + switch (endingUnit) + { + case 0: //miles to miles + return distance; + break; + + case 1: //miles to kilometer + return distance * 1,60934; + break; + + default: + break; + } + + case 1: //kilometer to x + switch (endingUnit) + { + case 0: //kilometer to miles + return distance / 1, 60934; + break; + + case 1: //kilometer to kilometer + return distance; + break; + + default: + break; + } + + default: + break; + } } double ConGram() { From 77a2938724673e28b3d00714b3e10399737421a2 Mon Sep 17 00:00:00 2001 From: Enrico Schellenberger Date: Mon, 5 Feb 2024 19:22:55 +0100 Subject: [PATCH 3/5] 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 From 0b2e6fb73dc33ee82444c8586edb6d902b91daef Mon Sep 17 00:00:00 2001 From: Enrico Schellenberger Date: Mon, 5 Feb 2024 19:44:22 +0100 Subject: [PATCH 4/5] added ConGram logic --- src/main/c/ConvertMode.c | 107 ++++++++++++++++++++++++++++++++++++--- 1 file changed, 101 insertions(+), 6 deletions(-) diff --git a/src/main/c/ConvertMode.c b/src/main/c/ConvertMode.c index 4b8333d..f18e08f 100644 --- a/src/main/c/ConvertMode.c +++ b/src/main/c/ConvertMode.c @@ -78,8 +78,6 @@ double getValue(int choice) { 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); @@ -87,13 +85,14 @@ double getValue(int choice) { 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); + result = ConGram(value, startingUnit, endingUnit); printf("\nThe convertet result is %dlf %d", result, Distance[endingUnit]); break; + } } - } + } double ConMeter(double meter, int startingUnit, int endingUnit) { @@ -272,8 +271,104 @@ double ConKilometerToMiles(double distance, int startingUnit, int endingUnit) { } } -double ConGram() { - +double ConGram(double weight, int startingUnit, int endingUnit) { + switch (startingUnit) + {//'mg', 'g', 'kg', 't' + case 0: //mg to x + switch (endingUnit) + { + case 0: //1 + return weight; + break; + + case 1: //0.001 + return weight / 1000; + break; + + case 2: //0.000001 + return weight / 1000000; + break; + + case 3: //0.000000001 + return weight / 1000000000; + break; + + default: + break; + } + + case 1: //g to x + switch (endingUnit) + { + case 0: //1000 + return weight * 1000; + break; + + case 1: //1 + return weight; + break; + + case 2: //0.01 + return weight / 100; + break; + + case 3: //0.000001 + return weight / 100000; + break; + + default: + break; + } + + case 2: //kg to x + switch (endingUnit) + { + case 0: //1000 + return weight * 1000; + break; + + case 1: //100 + return weight * 100; + break; + + case 2: //1 + return weight; + break; + + case 3: //0.001 + return weight / 1000; + break; + + default: + break; + } + + case 3://t to x + switch (endingUnit) + { + case 0: // 1000000000 + return weight * 1000000; + break; + + case 1: // 1000000 + return weight * 100000; + break; + + case 2: // 1000 + return weight * 1000; + break; + + case 3: //1 + return weight; + break; + + default: + break; + } + + default: + break; + } } double ConTemp() { From a042bb6743e991b747fb71be0418ed8a1757a6f1 Mon Sep 17 00:00:00 2001 From: Enrico Schellenberger Date: Mon, 5 Feb 2024 19:56:27 +0100 Subject: [PATCH 5/5] added ConTemp logic --- src/main/c/ConvertMode.c | 51 ++++++++++++++++++++++++++++++++++++++-- 1 file changed, 49 insertions(+), 2 deletions(-) diff --git a/src/main/c/ConvertMode.c b/src/main/c/ConvertMode.c index f18e08f..f50e6e6 100644 --- a/src/main/c/ConvertMode.c +++ b/src/main/c/ConvertMode.c @@ -13,6 +13,7 @@ double value, result; char Distance[] = { 'mm', 'cm', 'm', 'km', 'feet/inch', 'miles'}; char Weight[] = { 'mg', 'g', 'kg', 't' }; char Fluid[] = { 'ml', 'l' }; +char Temp[] = {'celsius', 'fahrenheit'} char Data[] = { 'B', 'KB', 'MB', 'GB', 'TB', 'PT' }; char Time[] = { 'ms', 's', 'min', 'h', 'd', 'w', 'mon', 'y' }; char currency[] = { 'E', 'D', 'R' }; @@ -90,6 +91,18 @@ double getValue(int choice) { printf("\nThe convertet result is %dlf %d", result, Distance[endingUnit]); break; + case 5://'celsius', 'fahrenheit' + printf("\nEnter what the Unit is starting with (0 celsius, 1 fahrenheit): "); + scanf("%d", &startingUnit); + + printf("\nEnter what the value should it be changed to (0 celsius, 1 fahrenheit): "); + scanf("%d", &endingUnit); + + result = ConTemp(value, startingUnit, endingUnit); + + printf("\nThe convertet result is %dlf %d", result, Distance[endingUnit]); + break; + } } @@ -371,8 +384,42 @@ double ConGram(double weight, int startingUnit, int endingUnit) { } } -double ConTemp() { - +double ConTemp(double Temp, int startingUnit, int endingUnit) { + switch (startingUnit) + { + case 0: //celsius to x + switch (endingUnit) + { + case 0: //celsius to fahrenheit + return Temp = (Temp - 32) * 0, 55555555; + break; + + case 1: //celsius to celsius + return Temp; + break; + + default: + break; + } + + case 1: //fahrenheit to x + switch (endingUnit) + { + case 0: //fahrenheit to celsius + return Temp = (Temp * 1,8) + 32; + break; + + case 1: //fahrenheit to fahrenheit + return Temp; + break; + + default: + break; + } + + default: + break; + } } double ConSpeed() {