Browse Source

fixed error with case 2 and 3 that wrong unit is shown

remotes/origin/feature
Enrico Schellenberger 11 months ago
parent
commit
77a2938724
  1. 35
      src/main/c/ConvertMode.c

35
src/main/c/ConvertMode.c

@ -10,7 +10,7 @@
int choice, startingUnit, endingUnit; int choice, startingUnit, endingUnit;
double value, result; 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 Weight[] = { 'mg', 'g', 'kg', 't' };
char Fluid[] = { 'ml', 'l' }; char Fluid[] = { 'ml', 'l' };
char Data[] = { 'B', 'KB', 'MB', 'GB', 'TB', 'PT' }; char Data[] = { 'B', 'KB', 'MB', 'GB', 'TB', 'PT' };
@ -46,6 +46,15 @@ double getValue(int choice) {
result = ConMeterToFoot(value, startingUnit, 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]); printf("\nThe convertet result is %dlf %d", result, Distance[endingUnit]);
break; break;
@ -58,6 +67,28 @@ double getValue(int choice) {
result = ConKilometerToMiles(value, startingUnit, 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 = ConKilometerToMiles(value, startingUnit, endingUnit);
printf("\nThe convertet result is %dlf %d", result, Distance[endingUnit]); printf("\nThe convertet result is %dlf %d", result, Distance[endingUnit]);
break; 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) switch (startingUnit)
{ {
case 0: //miles to x case 0: //miles to x

Loading…
Cancel
Save