fork download
  1. #include <stdio.h>
  2. #include <string.h>
  3.  
  4. int main(void)
  5. {
  6. double value;
  7. char from[30];
  8. char to[30];
  9. double result;
  10.  
  11. printf("Enter value: ");
  12. scanf("%lf", &value);
  13.  
  14. printf("Enter source unit: ");
  15. scanf("%29s", from);
  16.  
  17. printf("Enter target unit: ");
  18. scanf("%29s", to);
  19.  
  20. if (strcmp(from, "meters") == 0 &&
  21. strcmp(to, "feet") == 0)
  22. {
  23. result = value * 3.28084;
  24. }
  25. else if (strcmp(from, "feet") == 0 &&
  26. strcmp(to, "meters") == 0)
  27. {
  28. result = value / 3.28084;
  29. }
  30. else if (strcmp(from, "kilograms") == 0 &&
  31. strcmp(to, "pounds") == 0)
  32. {
  33. result = value * 2.20462;
  34. }
  35. else if (strcmp(from, "pounds") == 0 &&
  36. strcmp(to, "kilograms") == 0)
  37. {
  38. result = value / 2.20462;
  39. }
  40. else if (strcmp(from, "liters") == 0 &&
  41. strcmp(to, "gallons") == 0)
  42. {
  43. result = value * 0.264172;
  44. }
  45. else if (strcmp(from, "gallons") == 0 &&
  46. strcmp(to, "liters") == 0)
  47. {
  48. result = value / 0.264172;
  49. }
  50. else
  51. {
  52. printf("Invalid conversion.\n");
  53. return 0;
  54. }
  55.  
  56. printf("%.2f %s = %.2f %s\n",
  57. value, from, result, to);
  58.  
  59. return 0;
  60. }
Success #stdin #stdout 0s 5344KB
stdin
Standard input is empty
stdout
Enter value: Enter source unit: Enter target unit: Invalid conversion.