diff --git a/src/main/c/ConvertMode.c b/src/main/c/ConvertMode.c index 2d9e9ae..f50e6e6 100644 --- a/src/main/c/ConvertMode.c +++ b/src/main/c/ConvertMode.c @@ -10,9 +10,10 @@ 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 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' }; @@ -37,8 +38,74 @@ 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); + + 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; + + 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); + + 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 = ConGram(value, startingUnit, endingUnit); + + 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; + } } + } double ConMeter(double meter, int startingUnit, int endingUnit) { @@ -141,20 +208,218 @@ 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() { - +double ConKilometerToMiles(double distance, int startingUnit, int endingUnit) { + 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() { - +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() { - +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() {