|
|
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <stdbool.h>
#include "taschenrechner.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; } } } /*
double ConSpeed(double speed, int startingUnit, int endingUnit) { switch (startingUnit) { case 0: //kmh to x
switch (endingUnit) { case 0: //kmh to kmh
return speed; break;
case 1: //kmh to mph
return speed * 0.621371; break;
default: break; }
case 1: //mph to x
switch (endingUnit) { case 0: //mph to kmh
return speed * 1.60934; break;
case 1: //mph to mph
return speed; break;
default: break; }
default: break; } } */
double ConVolume() {
}
double ConTime() {
}
double ConClock() {
}
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) \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); }
|