From 4702603f1b7bce5c1e4d61806e6ccf1c18e84787 Mon Sep 17 00:00:00 2001 From: Enrico Schellenberger Date: Mon, 5 Feb 2024 20:12:33 +0100 Subject: [PATCH] added ConGramToPounds logic and fixed some errors in other functions --- src/main/c/ConvertMode.c | 66 +++++++++++++++++++++++++++++++++++----- 1 file changed, 59 insertions(+), 7 deletions(-) diff --git a/src/main/c/ConvertMode.c b/src/main/c/ConvertMode.c index f50e6e6..0ebb3ae 100644 --- a/src/main/c/ConvertMode.c +++ b/src/main/c/ConvertMode.c @@ -11,7 +11,7 @@ int choice, startingUnit, endingUnit; double value, result; char Distance[] = { 'mm', 'cm', 'm', 'km', 'feet/inch', 'miles'}; -char Weight[] = { 'mg', 'g', 'kg', 't' }; +char Weight[] = { 'mg', 'g', 'kg', 't', 'pounds'}; char Fluid[] = { 'ml', 'l' }; char Temp[] = {'celsius', 'fahrenheit'} char Data[] = { 'B', 'KB', 'MB', 'GB', 'TB', 'PT' }; @@ -91,7 +91,19 @@ double getValue(int choice) { printf("\nThe convertet result is %dlf %d", result, Distance[endingUnit]); break; - case 5://'celsius', 'fahrenheit' + case 5://'kg', 'pounds' + printf("\nEnter what the Unit is starting with (0 kg, 1 pounds): "); + scanf("%d", &startingUnit); + + printf("\nEnter what the value should it be changed to (0 kg, 1 pounds): "); + scanf("%d", &endingUnit); + + result = ConGramToPounds(value, startingUnit, endingUnit); + + printf("\nThe convertet result is %dlf %d", result, Distance[endingUnit]); + break; + + case 6://'celsius', 'fahrenheit' printf("\nEnter what the Unit is starting with (0 celsius, 1 fahrenheit): "); scanf("%d", &startingUnit); @@ -103,6 +115,8 @@ double getValue(int choice) { printf("\nThe convertet result is %dlf %d", result, Distance[endingUnit]); break; + + } } @@ -384,18 +398,56 @@ double ConGram(double weight, int startingUnit, int endingUnit) { } } -double ConTemp(double Temp, int startingUnit, int endingUnit) { +double ConGramToPounds(double weight, int startingUnit, int endingUnit) { + switch (startingUnit) + { + case 0: //kg to x + switch (endingUnit) + { + case 0: //kg to pounds + return weight *= 2.20462; + break; + + case 1: //kg to kg + return weight; + break; + + default: + break; + } + + case 1: //pounds to x + switch (endingUnit) + { + case 0: //pounds to kg + return weight *= 0,453592; + break; + + case 1: //pounds to pounds + return weight; + break; + + default: + break; + } + + default: + break; + } +} + +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; + return temp = (temp - 32) * 0, 55555555; break; case 1: //celsius to celsius - return Temp; + return temp; break; default: @@ -406,11 +458,11 @@ double ConTemp(double Temp, int startingUnit, int endingUnit) { switch (endingUnit) { case 0: //fahrenheit to celsius - return Temp = (Temp * 1,8) + 32; + return temp = (temp * 1,8) + 32; break; case 1: //fahrenheit to fahrenheit - return Temp; + return temp; break; default: