Browse Source

added ConGram logic

remotes/origin/feature
Enrico Schellenberger 11 months ago
parent
commit
0b2e6fb73d
  1. 103
      src/main/c/ConvertMode.c

103
src/main/c/ConvertMode.c

@ -78,8 +78,6 @@ double getValue(int choice) {
printf("\nThe convertet result is %dlf %d", result, Distance[endingUnit]); printf("\nThe convertet result is %dlf %d", result, Distance[endingUnit]);
break; break;
}
case 4://'mg', 'g', 'kg', 't' case 4://'mg', 'g', 'kg', 't'
printf("\nEnter what the Unit is starting with (0 mg, 1 g, 2 kg , 3 t): "); printf("\nEnter what the Unit is starting with (0 mg, 1 g, 2 kg , 3 t): ");
scanf("%d", &startingUnit); 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): "); printf("\nEnter what the value should it be changed to (0 mg, 1 g, 2 kg , 3 t): ");
scanf("%d", &endingUnit); scanf("%d", &endingUnit);
result = ConKilometerToMiles(value, startingUnit, endingUnit);
result = ConGram(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;
} }
} }
} }
double ConMeter(double meter, int startingUnit, int endingUnit) { 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() { double ConTemp() {

Loading…
Cancel
Save