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

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