Browse Source

added ConMeter logic to ConvertMode.c

remotes/origin/feature
Enrico Schellenberger 11 months ago
parent
commit
002a3cca80
  1. 106
      src/main/c/ConvertMode.c

106
src/main/c/ConvertMode.c

@ -9,6 +9,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' };
char Weight[] = { 'mg', 'g', 'kg', 't' }; char Weight[] = { 'mg', 'g', 'kg', 't' };
char Fluid[] = { 'ml', 'l' }; char Fluid[] = { 'ml', 'l' };
@ -16,6 +17,7 @@ char Data[] = { 'B', 'KB', 'MB', 'GB', 'TB', 'PT' };
char Time[] = { 'ms', 's', 'min', 'h', 'd', 'w', 'mon', 'y' }; char Time[] = { 'ms', 's', 'min', 'h', 'd', 'w', 'mon', 'y' };
char currency[] = { 'E', 'D', 'R' }; char currency[] = { 'E', 'D', 'R' };
double getValue(int choice) { double getValue(int choice) {
printf("\nEnter the value to be converted: "); printf("\nEnter the value to be converted: ");
scanf("%lf", &value); scanf("%lf", &value);
@ -24,15 +26,15 @@ double getValue(int choice) {
switch (choice) switch (choice)
{ {
case 1: case 1:
printf("\nEnter what the Unit is starting with: ");
printf("\nEnter what the Unit is starting with (0 mm, 1 cm, 2 m, 3 km): ");
scanf("%d", &startingUnit); scanf("%d", &startingUnit);
printf("\nEnter what the value should it be changed to: ");
//1 10 1.000 1.000.000
printf("\nEnter what the value should it be changed to (0 mm, 1 cm, 2 m, 3 km): ");
scanf("%d", &endingUnit); scanf("%d", &endingUnit);
result = ConMeter(value, startingUnit,endingUnit); result = ConMeter(value, startingUnit,endingUnit);
printf("\nThe convertet result is %dlf %d", result, Distance[unit]);
printf("\nThe convertet result is %dlf %d", result, Distance[endingUnit]);
break; break;
} }
@ -40,7 +42,103 @@ double getValue(int choice) {
} }
double ConMeter(double meter, int startingUnit, int endingUnit) { double ConMeter(double meter, int startingUnit, int endingUnit) {
switch (startingUnit)
{
case 0: //mm to x
switch (endingUnit)
{
case 0: //1mm
return meter;
break;
case 1: //0.1cm
return meter/10;
break;
case 2: //0.001m
return meter/1000;
break;
case 3: //0.000001km
return meter/1000000;
break;
default:
break;
}
case 1: //cm to x
switch (endingUnit)
{
case 0: //10
return meter*10;
break;
case 1: //1
return meter;
break;
case 2: //0.01
return meter/100;
break;
case 3: //0.00001
return meter/100000;
break;
default:
break;
}
case 2: //m to x
switch (endingUnit)
{
case 0: //1000
return meter*1000;
break;
case 1: //100
return meter*100;
break;
case 2: //1
return meter;
break;
case 3: //0.001
return meter/1000;
break;
default:
break;
}
case 3:// km to x
switch (endingUnit)
{
case 0: // 1000000
return meter*1000000;
break;
case 1: // 100000
return meter*100000;
break;
case 2: // 1000 m
return meter*1000;
break;
case 3: //1 km
return meter;
break;
default:
break;
}
default:
break;
}
} }
double ConMeterToFoot() { double ConMeterToFoot() {

Loading…
Cancel
Save