diff --git a/src/main/c/ConvertMode.c b/src/main/c/ConvertMode.c index 2d9e9ae..5ce125c 100644 --- a/src/main/c/ConvertMode.c +++ b/src/main/c/ConvertMode.c @@ -10,11 +10,13 @@ int choice, startingUnit, endingUnit; double value, result; -char Distance[] = { 'mm', 'cm', 'm', 'km' }; -char Weight[] = { 'mg', 'g', 'kg', 't' }; -char Fluid[] = { 'ml', 'l' }; +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 Time[] = { 'ms', 's', 'min', 'h', 'd', 'w', 'mon', 'y'}; char currency[] = { 'E', 'D', 'R' }; @@ -37,158 +39,182 @@ double getValue(int choice) { 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); -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; - } -} + printf("\nEnter what the value should it be changed to (0 feet/Inch, 1 meter): "); + scanf("%d", &endingUnit); -double ConMeterToFoot() { - -} + result = ConMeterToFoot(value, startingUnit, endingUnit); + + if (endingUnit == 0) { //if feet/inch change to 4. in array of Distance + endingUnit = 4; + } -double ConKilometerToMiles() { + else if (endingUnit == 1) { //if meter change to 2. in array of Distance + endingUnit = 2; + } -} -double ConGram() { + 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); -double ConTemp() { + printf("\nEnter what the value should it be changed to (0 miles, 1 kilometer): "); + scanf("%d", &endingUnit); -} + result = ConKilometerToMiles(value, startingUnit, endingUnit); -double ConSpeed() { + 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; + } -double ConLiter() { + 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); -double ConLiterToGallon() { + 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); -double ConData() { + 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); -double ConArea() { + printf("\nEnter what the value should it be changed to (0 kg, 1 pounds): "); + scanf("%d", &endingUnit); -} + result = ConGramToPounds(value, startingUnit, endingUnit); -double ConVolume() { + 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); -double ConTime() { + printf("\nEnter what the value should it be changed to (0 celsius, 1 fahrenheit): "); + scanf("%d", &endingUnit); -} + result = ConTemp(value, startingUnit, endingUnit); -double ConClock() { + 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() { @@ -201,7 +227,7 @@ void unitConverterMode() { printf("Weight conversion:\n"); printf("4. Convert Gram (mg, g, kg)\n"); - printf("5. Gram to Pounds \n") + printf("5. Gram to Pounds \n"); printf("Temprature conversion:\n"); printf("6. Celsius to Fahrenheit\n"); @@ -221,7 +247,7 @@ void unitConverterMode() { printf("12. Convert Volume (cm³, m³, km³)\n"); printf("Time conversion \n"); - printf("13. Convert time (s, m, h) \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"); diff --git a/src/main/c/main_taschenrechner.c b/src/main/c/main_taschenrechner.c index cf35f78..414021b 100644 --- a/src/main/c/main_taschenrechner.c +++ b/src/main/c/main_taschenrechner.c @@ -5,6 +5,7 @@ #include "taschenrechner.h" + double add(double a, double b) { return a + b; } @@ -18,7 +19,6 @@ double multiply(double a, double b) { } double divide(double a, double b) { - if (b == 0) { return 0; } @@ -88,8 +88,1229 @@ int bitwiseXOR(int num1, int num2) { return num1 ^ num2; } -//.. +//Conversion Functions +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 ConArea(double area, int startingUnit, int endingUnit) { + switch (startingUnit) + { + case 0: //mm to x + switch (endingUnit) + { + case 0: //1mm + return area; + break; + + case 1: //0.01cm + return area / 100; + break; + + case 2: //0.000001m + return area / 1000000; + break; + + case 3: //0.000000000001km + return area / 1000000000000; + break; + + default: + break; + } + + case 1: //cm to x + switch (endingUnit) + { + case 0: //100 + return area * 100; + break; + + case 1: //1 + return area; + break; + + case 2: //0.0001 + return area / 10000; + break; + + case 3: //0.0000000001 + return area / 10000000000; + break; + + default: + break; + } + + case 2: //m to x + switch (endingUnit) + { + case 0: //1000000 + return area * 1000000; + break; + + case 1: //10000 + return area * 10000; + break; + + case 2: //1 + return area; + break; + + case 3: //0.000001 + return area / 1000000; + break; + + default: + break; + } + + case 3:// km to x + switch (endingUnit) + { + case 0: // 1000000000000 + return area * 1000000000000; + break; + + case 1: // 10000000000 + return area * 10000000000; + break; + + case 2: // 1000000 m + return area * 1000000; + break; + + case 3: //1 km + return area; + break; + + default: + break; + } + + default: + break; + } +} + +double ConMeterToFoot(double distance, int startingUnit, int endingUnit) { + switch (startingUnit) + { + case 0: //feet/inch to x + switch (endingUnit) + { + case 0: //feet/inch to feet/inch + return distance; + break; + + case 1: //feet/inch to meter + return distance / 3. 28084; + break; + + default: + break; + } + + case 1: //meter to x + switch (endingUnit) + { + case 0: //meter to feet/inch + return distance * 3. 28084; + break; + + case 1: //feet/inch to feet/inch + return distance; + break; + + default: + break; + } + + default: + break; + } +} + +double ConKilometerToMiles(double distance, int startingUnit, int endingUnit) { + switch (startingUnit) + { + case 0: //miles to x + switch (endingUnit) + { + case 0: //miles to miles + return distance; + break; + + case 1: //miles to kilometer + return distance * 1. 60934; + break; + + default: + break; + } + + case 1: //kilometer to x + switch (endingUnit) + { + case 0: //kilometer to miles + return distance / 1. 60934; + break; + + case 1: //kilometer to kilometer + return distance; + break; + + default: + break; + } + + default: + break; + } +} + +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 ConGramToPounds(double weight, int startingUnit, int endingUnit) { + switch (startingUnit) + { + case 0: //kg to x + switch (endingUnit) + { + case 0: //kg to pounds + return weight *= 2.20462; + break; + + case 1: //kg to kg + return weight; + break; + + default: + break; + } + + case 1: //pounds to x + switch (endingUnit) + { + case 0: //pounds to kg + return weight *= 0, 453592; + break; + + case 1: //pounds to pounds + return weight; + break; + + default: + break; + } + + default: + break; + } +} + +double ConTemp(double temp, int startingUnit, int endingUnit) { + switch (startingUnit) + { + case 0: //celsius to x + switch (endingUnit) + { + case 0: //celsius to fahrenheit + return temp = (temp - 32) * 0, 55555555; + break; + + case 1: //celsius to celsius + return temp; + break; + + default: + break; + } + + case 1: //fahrenheit to x + switch (endingUnit) + { + case 0: //fahrenheit to celsius + return temp = (temp * 1, 8) + 32; + break; + + case 1: //fahrenheit to fahrenheit + return temp; + break; + + default: + break; + } + + default: + 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 ConLiter(double liter, int startingUnit, int endingUnit) { + switch (startingUnit) + { + case 0: //ml to x + switch (endingUnit) + { + case 0: //ml to ml + return liter; + break; + + case 1: //ml to l + return liter / 1000; + break; + + default: + break; + } + + case 1: //l to x + switch (endingUnit) + { + case 0: //l to ml + return liter * 1000; + break; + + case 1: //l to l + return liter; + break; + + default: + break; + } + + default: + break; + } +} + +double ConLiterToGallon(double fluid, int startingUnit, int endingUnit) { + switch (startingUnit) + { + case 0: //l to x + switch (endingUnit) + { + case 0: //l to l + return fluid; + break; + + case 1: //l to gallon + return fluid * 0.264172; + break; + + default: + break; + } + + case 1: //gallon to x + switch (endingUnit) + { + case 0: //gallon to l + return fluid * 3.78541; + break; + + case 1: //gallon to gallon + return fluid; + break; + + default: + break; + } + + default: + break; + } +} + +double ConData(double data, int startingUnit, int endingUnit) { + switch (startingUnit) + {//'B', 'KB', 'MB', 'GB', 'TB', 'PT' + case 0: //B to x + switch (endingUnit) + { + case 0: //1 + return data; + break; + + case 1: //0.001 + return data / 1000; + break; + + case 2: //0.000001 + return data / 1000000; + break; + + case 3: //0.000000001 + return data / 1000000000; + break; + + case 4: //0.000000000001 + return data / 1000000000000; + break; + + case 5: //0.000000000000001 + return data / 1000000000000000; + break; + + default: + break; + } + + case 1: //KB to x + switch (endingUnit) + { + case 0: //1000 + return data * 1000; + break; + + case 1: //1 + return data; + break; + + case 2: //0.001 + return data / 1000; + break; + + case 3: //0.000001 + return data / 1000000; + break; + case 4: //0.000000001 + return data / 1000000000; + break; + + case 5: //0.000000000001 + return data / 1000000000000; + break; + + default: + break; + } + + case 2: //MB to x + switch (endingUnit) + { + case 0: //0.000001 + return data * 1000000; + break; + + case 1: //0.001 + return data * 1000; + break; + + case 2: //1 + return data; + break; + + case 3: //0.001 + return data / 1000; + break; + + case 4: //0.000001 + return data / 1000000; + break; + + case 5: //0.000000001 + return data / 1000000000; + break; + + default: + break; + } + + + case 3: //GB to x + switch (endingUnit) + { + case 0: //0.000000001 + return data * 1000000000; + break; + + case 1: //0.000001 + return data * 1000000; + break; + + case 2: //1000 + return data * 1000;; + break; + + case 3: //1 + return data; + break; + + case 4: //0.001 + return data / 1000; + break; + + case 5: //0.000001 + return data / 1000000; + break; + + default: + break; + } + + + case 4: //TB to x + switch (endingUnit) + { + case 0: //0.000000000001 + return data * 1000000000000; + break; + + case 1: //0.000000001 + return data * 1000000000; + break; + + case 2: //1000000 + return data * 1000000;; + break; + + case 3: //1000 + return data * 1000; + break; + + case 4: //1 + return; + break; + + case 5: //0.001 + return data / 1000; + break; + + default: + break; + } + + + case 5: //PB to x + switch (endingUnit) + { + case 0: //0.000000000000001 + return data * 1000000000000000; + break; + + case 1: //0.000000000001 + return data * 1000000000000; + break; + + case 2: //1000000000 + return data * 1000000000;; + break; + + case 3: //1000000 + return data * 1000000; + break; + + case 4: //1000 + return data * 1000; + break; + + case 5: //1 + return data; + break; + + default: + break; + } + } +} + +double ConVolume(double volum, int startingUnit, int endingUnit) { + switch (startingUnit) + { + case 0: //mm to x + switch (endingUnit) + { + case 0: //1mm + return volum; + break; + + case 1: //0.001cm + return volum / 1000; + break; + + case 2: //0.000000001m + return volum / 1000000000; + break; + + case 3: //0.000000000000001km + return volum / 1000000000000000000; + break; + + default: + break; + } + + case 1: //cm to x + switch (endingUnit) + { + case 0: //1000 + return volum * 1000; + break; + + case 1: //1 + return volum; + break; + + case 2: //0.000001 + return volum / 1000000; + break; + + case 3: //0.0000000000001 + return volum / 1000000000000000; + break; + + default: + break; + } + + case 2: //m to x + switch (endingUnit) + { + case 0: //100000000 + return volum * 1000000000; + break; + + case 1: //1000000 + return volum * 1000000; + break; + + case 2: //1 + return volum; + break; + + case 3: //0.000000001 + return volum / 1000000000; + break; + + default: + break; + } + + case 3:// km to x + switch (endingUnit) + { + case 0: // 1000000000000000000 + return volum * 1000000000000000000; + break; + + case 1: // 1000000000000000 + return volum * 1000000000000000; + break; + + case 2: // 1000000000 m + return volum * 1000000000; + break; + + case 3: //1 km + return volum; + break; + + default: + break; + } + + default: + break; + } +} +double ConClock(double time, int startingUnit, int endingUnit) { + switch (startingUnit) + { + case 0: //24 to x + switch (endingUnit) + { + case 0: //24 to 24 + return time; + break; + + case 1: //24 to 12 + if (time > 12) { + return time -12; + } + + else { + return time + } + break; + + default: + break; + } + + case 1: //12 to x + switch (endingUnit) + { + case 0: //12 to 24 + return time + 12; + break; + + case 1: //12 to 12 + return time; + break; + + default: + break; + } + + default: + break; + } +} + +double ConTime(double time, int startingUnit, int endingUnit) { + switch (startingUnit) + {//'ms', 's', 'min', 'h', 'd', 'w', 'mon', 'y' + case 0: //ms to x + switch (endingUnit) + { + case 0: //ms + return time; + break; + + case 1: //s + return time / 1000; + break; + + case 2: //min + return time / (1000 * 60); + break; + + case 3: //h + return time / (1000 * 60 * 60); + break; + + case 4: //d + return time / (1000 * 60 * 60 * 24); + break; + + case 5: //w + return time / (1000 * 60 * 60 * 24 * 7); + break; + + case 6: //mon + return time / (1000 * 60 * 60 * 24 * 7 * 30); + break; + + case 7: //y + return time / (1000 * 60 * 60 * 24 * 7 * 30 * 12); + break; + + default: + break; + } + + case 1: //s to x + switch (endingUnit) + { + case 0: //ms + return time * 1000; + break; + + case 1: //s + return time; + break; + + case 2: //min + return time / 60; + break; + + case 3: //h + return time / (60 * 60); + break; + + case 4: //d + return time / (60 * 60 * 24); + break; + + case 5: //w + return time / (60 * 60 * 24 * 7); + break; + + case 6: //mon + return time / (60 * 60 * 24 * 7 * 30); + break; + + case 7: //y + return time / (60 * 60 * 24 * 7 * 30 * 12); + break; + + default: + break; + } + + case 2: //min to x + switch (endingUnit) + { + case 0: //ms + return time * 1000; + break; + + case 1: //s + return time * 1000 * 60; + break; + + case 2: //min + return time; + break; + + case 3: //h + return time / 60; + break; + + case 4: //d + return time / (60 * 24); + break; + + case 5: //w + return time / (60 * 24 * 7); + break; + + case 6: //mon + return time / (60 * 24 * 7 * 4); + break; + + case 7: //y + return time / 60 * 24 * 7 * 4 * 12); + break; + + default: + break; + } + + case 3: //h to x + switch (endingUnit) + { + case 0: //ms + return time * 1000 * 60 * 60; + break; + + case 1: //s + return time * 60 * 60; + break; + + case 2: //min + return time * 60; + break; + + case 3: //h + return time; + break; + + case 4: //d + return time / 24; + break; + + case 5: //w + return time / (24 * 7); + break; + + case 6: //mon + return time / (24 * 7 * 4); + break; + + case 7: //y + return time / (24 * 7 * 4 * 12); + break; + + default: + break; + } + + case 4: //d to x + switch (endingUnit) + { + case 0: //ms + return time * 1000 * 60 * 60 * 24; + break; + + case 1: //s + return time * 60 * 60 * 24; + break; + + case 2: //min + return time * 60 * 24; + break; + + case 3: //h + return time * 24; + break; + + case 4: //d + return time; + break; + + case 5: //w + return time / 7; + break; + + case 6: //mon + return time / (7 * 4); + break; + + case 7: //y + return time / (7 * 4 * 12); + break; + + default: + break; + } + + case 5: //w to x + switch (endingUnit) + { + case 0: //ms + return time * 1000 * 60 * 60 * 24 * 7; + break; + + case 1: //s + return time * 60 * 60 * 24 * 7; + break; + + case 2: //min + return time * 60 * 24 * 7; + break; + + case 3: //h + return time * 24 * 7; + break; + + case 4: //d + return time * 7; + break; + + case 5: //w + return time; + break; + + case 6: //mon + return time / 4; + break; + + case 7: //y + return time / (4 * 12); + break; + + default: + break; + } + + case 6: //mon to x + switch (endingUnit) + { + case 0: //ms + return time * 1000 * 60 * 60 * 24 * 7 * 4; + break; + + case 1: //s + return time * 60 * 60 * 24 * 7 * 4; + break; + + case 2: //min + return time * 60 * 24 * 7 * 4; + break; + + case 3: //h + return time * 24 * 7 * 4; + break; + + case 4: //d + return time * 7 * 4; + break; + + case 5: //w + return time * 4; + break; + + case 6: //mon + return time; + break; + + case 7: //y + return time / 12; + break; + + default: + break; + } + + case 7: //y to x + switch (endingUnit) + { + case 0: //ms + return time * 1000 * 60 * 60 * 24 * 7 * 4 * 12; + break; + + case 1: //s + return time * 60 * 60 * 24 * 7 * 4 * 12; + break; + + case 2: //min + return time * 60 * 24 * 7 * 4 * 12; + break; + + case 3: //h + return time * 24 * 7 * 4 * 12; + break; + + case 4: //d + return time * 7 * 4 * 12; + break; + + case 5: //w + return time * 4 * 12; + break; + + case 6: //mon + return time * 12); + break; + + case 7: //y + return time; + break; + //(1000 * 60 * 60 * 24 * 7 * 4 * 12) + default: + break; + } + } +} + + +//.. // graphMode void graphMode() { double x, y; @@ -109,25 +1330,6 @@ void graphMode() { } } -// Programming mode - -void programmingMode() { - - int num1, num2, result; - char operator; - - printf("Enter first integer: "); - scanf("%d", &num1); - - printf("Enter operator (+, -, *, /): "); - scanf(" %c", &operator); - - printf("Enter second integer: "); - scanf("%d", &num2); - -} - - // change mode int mode(int userChoice){ diff --git a/src/main/c/programmingMode.c b/src/main/c/programmingMode.c new file mode 100644 index 0000000..e89a75c --- /dev/null +++ b/src/main/c/programmingMode.c @@ -0,0 +1,23 @@ +// programmingMode + +#include +#include + +#include "taschenrechner.h" + + +void programmingMode() { + + int num1, num2, result; + char operator; + + printf("Enter first integer: "); + scanf("%d", &num1); + + printf("Enter operator (+, -, *, /): "); + scanf(" %c", &operator); + + printf("Enter second integer: "); + scanf("%d", &num2); + +} diff --git a/src/main/c/taschenrechner.h b/src/main/c/taschenrechner.h index 6382ac0..78ef6a1 100644 --- a/src/main/c/taschenrechner.h +++ b/src/main/c/taschenrechner.h @@ -56,4 +56,34 @@ int mode(int userChoice); int displayMenu(); -#endif // TASCHENRECHNER_H +//Conversion Functions +double ConMeter(double meter, int startingUnit, int endingUnit); + +double ConMeterToFoot(double distance, int startingUnit, int endingUnit); + +double ConKilometerToMiles(double distance, int startingUnit, int endingUnit); + +double ConGram(double weight, int startingUnit, int endingUnit); + +double ConGramToPounds(double weight, int startingUnit, int endingUnit); + +double ConTemp(double temp, int startingUnit, int endingUnit); + +double ConSpeed(double speed, int startingUnit, int endingUnit); + +double ConLiter(double liter, int startingUnit, int endingUnit); + +double ConLiterToGallon(double fluid, int startingUnit, int endingUnit); + +double ConData(double data, int startingUnit, int endingUnit); + +double ConArea(double area, int startingUnit, int endingUnit); + +double ConVolume(double volum, int startingUnit, int endingUnit); + +double ConClock(double time, int startingUnit, int endingUnit); + +double ConTime(double time, int startingUnit, int endingUnit); + + +#endif // TASCHENRECHNER_H