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.

275 lines
8.4 KiB

  1. #include <stdio.h>
  2. #include <string.h>
  3. #include <stdlib.h>
  4. #include <math.h>
  5. #include <stdbool.h>
  6. #include "taschenrechner.h"
  7. // Unit converter mode
  8. int choice, startingUnit, endingUnit;
  9. double value, result;
  10. char Distance[] = { 'mm', 'cm', 'm', 'km', 'feet/inch', 'miles'};
  11. char Weight[] = { 'mg', 'g', 'kg', 't', 'pounds'};
  12. char Fluid[] = { 'ml', 'l' , 'gallon'};
  13. char Temp[] = { 'celsius', 'fahrenheit' };
  14. char Speed[] = { 'km/h','mp/h' };
  15. char Data[] = { 'B', 'KB', 'MB', 'GB', 'TB', 'PT' };
  16. char Time[] = { 'ms', 's', 'min', 'h', 'd', 'w', 'mon', 'y' };
  17. char currency[] = { 'E', 'D', 'R' };
  18. double getValue(int choice) {
  19. printf("\nEnter the value to be converted: ");
  20. scanf("%lf", &value);
  21. while (choice < 0 && choice >= 15) {
  22. switch (choice)
  23. {
  24. case 1:
  25. printf("\nEnter what the Unit is starting with (0 mm, 1 cm, 2 m, 3 km): ");
  26. scanf("%d", &startingUnit);
  27. //1 10 1.000 1.000.000
  28. printf("\nEnter what the value should it be changed to (0 mm, 1 cm, 2 m, 3 km): ");
  29. scanf("%d", &endingUnit);
  30. result = ConMeter(value, startingUnit,endingUnit);
  31. printf("\nThe convertet result is %dlf %d", result, Distance[endingUnit]);
  32. break;
  33. case 2:
  34. printf("\nEnter what the Unit is starting with (0 feet/Inch, 1 meter): ");
  35. scanf("%d", &startingUnit);
  36. printf("\nEnter what the value should it be changed to (0 feet/Inch, 1 meter): ");
  37. scanf("%d", &endingUnit);
  38. result = ConMeterToFoot(value, startingUnit, endingUnit);
  39. if (endingUnit == 0) { //if feet/inch change to 4. in array of Distance
  40. endingUnit = 4;
  41. }
  42. else if (endingUnit == 1) { //if meter change to 2. in array of Distance
  43. endingUnit = 2;
  44. }
  45. printf("\nThe convertet result is %dlf %d", result, Distance[endingUnit]);
  46. break;
  47. case 3:
  48. printf("\nEnter what the Unit is starting with (0 miles, 1 kilometer): ");
  49. scanf("%d", &startingUnit);
  50. printf("\nEnter what the value should it be changed to (0 miles, 1 kilometer): ");
  51. scanf("%d", &endingUnit);
  52. result = ConKilometerToMiles(value, startingUnit, endingUnit);
  53. if (endingUnit == 0) { //if miles change to 5. in array of Distance
  54. endingUnit = 5;
  55. }
  56. else if (endingUnit == 1) { //if kilometer change to 2. in array of Distance
  57. endingUnit = 3;
  58. }
  59. printf("\nThe convertet result is %dlf %d", result, Distance[endingUnit]);
  60. break;
  61. case 4://'mg', 'g', 'kg', 't'
  62. printf("\nEnter what the Unit is starting with (0 mg, 1 g, 2 kg , 3 t): ");
  63. scanf("%d", &startingUnit);
  64. printf("\nEnter what the value should it be changed to (0 mg, 1 g, 2 kg , 3 t): ");
  65. scanf("%d", &endingUnit);
  66. result = ConGram(value, startingUnit, endingUnit);
  67. printf("\nThe convertet result is %dlf %d", result, Weight[endingUnit]);
  68. break;
  69. case 5://'kg', 'pounds'
  70. printf("\nEnter what the Unit is starting with (0 kg, 1 pounds): ");
  71. scanf("%d", &startingUnit);
  72. printf("\nEnter what the value should it be changed to (0 kg, 1 pounds): ");
  73. scanf("%d", &endingUnit);
  74. result = ConGramToPounds(value, startingUnit, endingUnit);
  75. printf("\nThe convertet result is %dlf %d", result, Weight[endingUnit]);
  76. break;
  77. case 6://'celsius', 'fahrenheit'
  78. printf("\nEnter what the Unit is starting with (0 celsius, 1 fahrenheit): ");
  79. scanf("%d", &startingUnit);
  80. printf("\nEnter what the value should it be changed to (0 celsius, 1 fahrenheit): ");
  81. scanf("%d", &endingUnit);
  82. result = ConTemp(value, startingUnit, endingUnit);
  83. printf("\nThe convertet result is %dlf %d", result, Temp[endingUnit]);
  84. break;
  85. case 7://'km/h','mp/h'
  86. printf("\nEnter what the Unit is starting with (0 km/h, 1 mp/h): ");
  87. scanf("%d", &startingUnit);
  88. printf("\nEnter what the value should it be changed to (0 km/h, 1 mp/h): ");
  89. scanf("%d", &endingUnit);
  90. result = ConSpeed(value, startingUnit, endingUnit);
  91. printf("\nThe convertet result is %dlf %d", result, Speed[endingUnit]);
  92. break;
  93. case 8://'ml', 'l'
  94. printf("\nEnter what the Unit is starting with (0 ml, 1 l): ");
  95. scanf("%d", &startingUnit);
  96. printf("\nEnter what the value should it be changed to (0 ml, 1 l): ");
  97. scanf("%d", &endingUnit);
  98. result = ConLiter(value, startingUnit, endingUnit);
  99. printf("\nThe convertet result is %dlf %d", result, Fluid[endingUnit]);
  100. break;
  101. case 9://'ml', 'l'
  102. printf("\nEnter what the Unit is starting with (0 l, 1 gallon): ");
  103. scanf("%d", &startingUnit);
  104. printf("\nEnter what the value should it be changed to (0 l, 1 gallon): ");
  105. scanf("%d", &endingUnit);
  106. result = ConLiterToGallon(value, startingUnit, endingUnit);
  107. printf("\nThe convertet result is %dlf %d", result, Fluid[endingUnit]);
  108. break;
  109. case 10://char Data[] = { 'B', 'KB', 'MB', 'GB', 'TB', 'PT' };
  110. printf("\nEnter what the Unit is starting with (0 B, 1 KB, 2 MB , 3 GB, 4 TB, 5 PT): ");
  111. scanf("%d", &startingUnit);
  112. printf("\nEnter what the value should it be changed to (0 B, 1 KB, 2 MB , 3 GB, 4 TB, 5 PT): ");
  113. scanf("%d", &endingUnit);
  114. result = ConData(value, startingUnit, endingUnit);
  115. printf("\nThe convertet result is %dlf %d", result, Data[endingUnit]);
  116. break;
  117. case 11://char Distance[] = { 'mm', 'cm', 'm', 'km', 'feet/inch', 'miles'};
  118. printf("\nEnter what the Unit is starting with (0 mm, 1 cm, 2 m , 3 km,): ");
  119. scanf("%d", &startingUnit);
  120. printf("\nEnter what the value should it be changed to (0 mm, 1 cm, 2 m , 3 km,): ");
  121. scanf("%d", &endingUnit);
  122. result = ConArea(value, startingUnit, endingUnit);
  123. printf("\nThe convertet result is %dlf %d�", result, Distance[endingUnit]);
  124. break;
  125. }
  126. }
  127. }
  128. /*
  129. double ConSpeed(double speed, int startingUnit, int endingUnit) {
  130. switch (startingUnit)
  131. {
  132. case 0: //kmh to x
  133. switch (endingUnit)
  134. {
  135. case 0: //kmh to kmh
  136. return speed;
  137. break;
  138. case 1: //kmh to mph
  139. return speed * 0.621371;
  140. break;
  141. default:
  142. break;
  143. }
  144. case 1: //mph to x
  145. switch (endingUnit)
  146. {
  147. case 0: //mph to kmh
  148. return speed * 1.60934;
  149. break;
  150. case 1: //mph to mph
  151. return speed;
  152. break;
  153. default:
  154. break;
  155. }
  156. default:
  157. break;
  158. }
  159. }
  160. */
  161. double ConVolume() {
  162. }
  163. double ConTime() {
  164. }
  165. double ConClock() {
  166. }
  167. void unitConverterMode() {
  168. printf("Unit Converter Mode:\n");
  169. printf("Distance conversions:\n");
  170. printf("1. Convert Meter (cm, m, km)\n");
  171. printf("2. Meter to foot/inches\n");
  172. printf("3. Kilometer to Miles\n");
  173. printf("Weight conversion:\n");
  174. printf("4. Convert Gram (mg, g, kg)\n");
  175. printf("5. Gram to Pounds \n")
  176. printf("Temprature conversion:\n");
  177. printf("6. Celsius to Fahrenheit\n");
  178. printf("Speed conversion:\n");
  179. printf("7. km/h to mph \n");
  180. printf("Fluid conversion:\n");
  181. printf("8. Convert Liter (ml, l, kl) \n");
  182. printf("9. Liter to Gallon\n");
  183. printf("Data conversions:\n");
  184. printf("10. Convert Data size (MB, GB, TB)\n");
  185. printf("Area/Volume conversions \n");
  186. printf("11. Convert area (cm�, m�, km�) \n");
  187. printf("12. Convert Volume (cm�, m�, km�)\n");
  188. printf("Time conversion \n");
  189. printf("13. Convert time (s, m, h) \n");
  190. printf("14. Convert Clock (12 Hour, 24 Hour) \n");
  191. printf("Time conversion \n");
  192. printf("15. Convert currency (Euro, Dollar, Russian Rubel) \n");
  193. printf("\nEnter your choice (Exit with 0): ");
  194. scanf("%d", &choice);
  195. getValue(choice);
  196. }