You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
258 lines
9.1 KiB
258 lines
9.1 KiB
#include <stdio.h>
|
|
#include <string.h>
|
|
#include <stdlib.h>
|
|
#include <math.h>
|
|
#include <stdbool.h>
|
|
|
|
// Unit converter mode
|
|
|
|
int choice, startingUnit, endingUnit;
|
|
double value, result;
|
|
|
|
char Distance[] = { 'mm', 'cm', 'm', 'km', 'feet/inch', 'miles'};
|
|
char Weight[] = { 'mg', 'g', 'kg', 't', 'pounds'};
|
|
char Fluid[] = { 'ml', 'l' , 'gallon'};
|
|
char Temp[] = { 'celsius', 'fahrenheit' };
|
|
char Speed[] = { 'km/h','mp/h' };
|
|
char Data[] = { 'B', 'KB', 'MB', 'GB', 'TB', 'PT' };
|
|
char Time[] = { 'ms', 's', 'min', 'h', 'd', 'w', 'mon', 'y'};
|
|
char currency[] = { 'E', 'D', 'R' };
|
|
|
|
|
|
double getValue(int choice) {
|
|
printf("\nEnter the value to be converted: ");
|
|
scanf("%lf", &value);
|
|
|
|
while (choice < 0 && choice >= 15) {
|
|
switch (choice)
|
|
{
|
|
case 1:
|
|
printf("\nEnter what the Unit is starting with (0 mm, 1 cm, 2 m, 3 km): ");
|
|
scanf("%d", &startingUnit);
|
|
//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);
|
|
|
|
result = ConMeter(value, startingUnit,endingUnit);
|
|
|
|
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, Weight[endingUnit]);
|
|
break;
|
|
|
|
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, Weight[endingUnit]);
|
|
break;
|
|
|
|
case 6://'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, Temp[endingUnit]);
|
|
break;
|
|
|
|
case 7://'km/h','mp/h'
|
|
printf("\nEnter what the Unit is starting with (0 km/h, 1 mp/h): ");
|
|
scanf("%d", &startingUnit);
|
|
|
|
printf("\nEnter what the value should it be changed to (0 km/h, 1 mp/h): ");
|
|
scanf("%d", &endingUnit);
|
|
|
|
result = ConSpeed(value, startingUnit, endingUnit);
|
|
|
|
printf("\nThe convertet result is %dlf %d", result, Speed[endingUnit]);
|
|
break;
|
|
|
|
case 8://'ml', 'l'
|
|
printf("\nEnter what the Unit is starting with (0 ml, 1 l): ");
|
|
scanf("%d", &startingUnit);
|
|
|
|
printf("\nEnter what the value should it be changed to (0 ml, 1 l): ");
|
|
scanf("%d", &endingUnit);
|
|
|
|
result = ConLiter(value, startingUnit, endingUnit);
|
|
|
|
printf("\nThe convertet result is %dlf %d", result, Fluid[endingUnit]);
|
|
break;
|
|
|
|
|
|
case 9://'ml', 'l'
|
|
printf("\nEnter what the Unit is starting with (0 l, 1 gallon): ");
|
|
scanf("%d", &startingUnit);
|
|
|
|
printf("\nEnter what the value should it be changed to (0 l, 1 gallon): ");
|
|
scanf("%d", &endingUnit);
|
|
|
|
result = ConLiterToGallon(value, startingUnit, endingUnit);
|
|
|
|
printf("\nThe convertet result is %dlf %d", result, Fluid[endingUnit]);
|
|
break;
|
|
|
|
case 10://char Data[] = { 'B', 'KB', 'MB', 'GB', 'TB', 'PT' };
|
|
printf("\nEnter what the Unit is starting with (0 B, 1 KB, 2 MB , 3 GB, 4 TB, 5 PT): ");
|
|
scanf("%d", &startingUnit);
|
|
|
|
printf("\nEnter what the value should it be changed to (0 B, 1 KB, 2 MB , 3 GB, 4 TB, 5 PT): ");
|
|
scanf("%d", &endingUnit);
|
|
|
|
result = ConData(value, startingUnit, endingUnit);
|
|
|
|
printf("\nThe convertet result is %dlf %d", result, Data[endingUnit]);
|
|
break;
|
|
|
|
case 11://char Distance[] = { 'mm', 'cm', 'm', 'km', 'feet/inch', 'miles'};
|
|
printf("\nEnter what the Unit is starting with (0 mm, 1 cm, 2 m , 3 km,): ");
|
|
scanf("%d", &startingUnit);
|
|
|
|
printf("\nEnter what the value should it be changed to (0 mm, 1 cm, 2 m , 3 km,): ");
|
|
scanf("%d", &endingUnit);
|
|
|
|
result = ConArea(value, startingUnit, endingUnit);
|
|
|
|
printf("\nThe convertet result is %dlf %d", result, Distance[endingUnit]);
|
|
break;
|
|
|
|
case 12://char Distance[] = { 'mm', 'cm', 'm', 'km', 'feet/inch', 'miles'};
|
|
printf("\nEnter what the Unit is starting with (0 mm, 1 cm, 2 m , 3 km,): ");
|
|
scanf("%d", &startingUnit);
|
|
|
|
printf("\nEnter what the value should it be changed to (0 mm, 1 cm, 2 m , 3 km,): ");
|
|
scanf("%d", &endingUnit);
|
|
|
|
result = ConArea(value, startingUnit, endingUnit);
|
|
|
|
printf("\nThe convertet result is %dlf %d", result, Distance[endingUnit]);
|
|
break;
|
|
|
|
case 13://char Time[] = { 'ms', 's', 'min', 'h', 'd', 'w', 'mon', 'y' };
|
|
printf("\nEnter what the Unit is starting with (0 ms, 1 s, 2 min, 3 h, 4 d, 5 w, 6 mon, 7 y): ");
|
|
scanf("%d", &startingUnit);
|
|
|
|
printf("\nEnter what the value should it be changed to (0 ms, 1 s, 2 min, 3 h, 4 d, 5 w, 6 mon, 7 y): ");
|
|
scanf("%d", &endingUnit);
|
|
|
|
result = ConTime(value, startingUnit, endingUnit);
|
|
|
|
printf("\nThe convertet result is %dlf %d", result, Distance[endingUnit]);
|
|
break;
|
|
|
|
case 14:
|
|
printf("\nEnter what the Unit is starting with (0 (24h), 1 (12h)): ");
|
|
scanf("%d", &startingUnit);
|
|
|
|
printf("\nEnter what the value should it be changed to (0 (24h), 1 (12h)): ");
|
|
scanf("%d", &endingUnit);
|
|
|
|
result = ConClock(value, startingUnit, endingUnit);
|
|
|
|
printf("\nThe convertet result is %dlf %d", result, Distance[endingUnit]);
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
|
|
void unitConverterMode() {
|
|
|
|
printf("Unit Converter Mode:\n");
|
|
|
|
printf("Distance conversions:\n");
|
|
printf("1. Convert Meter (cm, m, km)\n");
|
|
printf("2. Meter to foot/inches\n");
|
|
printf("3. Kilometer to Miles\n");
|
|
|
|
printf("Weight conversion:\n");
|
|
printf("4. Convert Gram (mg, g, kg)\n");
|
|
printf("5. Gram to Pounds \n");
|
|
|
|
printf("Temprature conversion:\n");
|
|
printf("6. Celsius to Fahrenheit\n");
|
|
|
|
printf("Speed conversion:\n");
|
|
printf("7. km/h to mph \n");
|
|
|
|
printf("Fluid conversion:\n");
|
|
printf("8. Convert Liter (ml, l, kl) \n");
|
|
printf("9. Liter to Gallon\n");
|
|
|
|
printf("Data conversions:\n");
|
|
printf("10. Convert Data size (MB, GB, TB)\n");
|
|
|
|
printf("Area/Volume conversions \n");
|
|
printf("11. Convert area (cm, m, km) \n");
|
|
printf("12. Convert Volume (cm, m, km)\n");
|
|
|
|
printf("Time conversion \n");
|
|
printf("13. Convert time (s, m, h, d, w, m, y) \n");
|
|
printf("14. Convert Clock (12 Hour, 24 Hour) \n");
|
|
|
|
printf("Time conversion \n");
|
|
printf("15. Convert currency (Euro, Dollar, Russian Rubel) \n");
|
|
|
|
printf("\nEnter your choice (Exit with 0): ");
|
|
scanf("%d", &choice);
|
|
getValue(choice);
|
|
}
|