Simple Conversion Program in C

How to write a Simple Conversion Program in C Programming Language ?

This is Simple Conversion Program in C Programming.


1. Temperature converter
2. Distance converter


Temperature conversion list


1. Convert Celsius to Fahrenheit 
2. Convert Fahrenheit to Celsius

Output: What is the degrees in Celsius?
Output: What is the degrees in Fahrenheit?

Distance conversion list

1. Convert Inches to Centimetres
2. Convert Centimetres to Inches
3. Convert Feet to Meters
4. Convert Meters to Feet

Output: What is the distance in Inches?
Output: What is the distance in Centimetres?
Output: What is the distance in feet?
Output: What is the distance in meters?


Solution:

  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. /* README
  4.     A simple conversion program
  5.     Coded by SmakGezgo
  6. */
  7. int main()
  8. {
  9.     // Main program select
  10.     int list;
  11.     int con;
  12.     printf("Select a list:\n 1. Temperature converter\n 2. Distance converter\n");
  13.     scanf( "%d", &list);
  14.     // Temperature conversion list
  15.     if(list == 1){
  16.         printf("Select a converter:\n 1. Celsius to Fahrenheit\n 2. Fahrenheit to Celsius\n");
  17.         scanf( "%d", &con);
  18.     // Fahrenhiet to Celsius
  19.         if(con == 1){
  20.             int cel;
  21.             printf("What is the degrees in Celsius? \n");
  22.             scanf("%d", &cel);
  23.         int fah = (cel * 1.8) + 32;
  24.         printf("%d degrees Celsius is equal to %d degrees Fahrenheit. \n", cel, fah);
  25.         }
  26.     // Celsius to Fahrenhiet
  27.         else if(con == 2){
  28.             int fah;
  29.             printf("What is the degrees in Fahrenheit? \n");
  30.             scanf("%d", &fah);
  31.         int cel = (fah - 32) * .5556;
  32.         printf("%d degrees Fahrenheit is equal to %d degrees Celsius. \n", fah, cel);
  33.         }
  34.     }
  35.     // Distance conversion list
  36.     if(list == 2){
  37.         printf("Select a converter:\n 1. Inches to Centimetres\n 2. Centimetres to Inches\n 3. Feet to Meters\n 4. Meters to Feet\n");
  38.         scanf( "%d", &con);
  39.     // Inches to Centimeters
  40.         if(con == 1){
  41.             float in;
  42.             printf("What is the distance in Inches? \n");
  43.             scanf("%f", &in);
  44.         float cm = (in * .39);
  45.         printf("%.2f Inches is equal to %.2f Centimetres. \n", in, cm);
  46.         }
  47.     // Centimeters to Inches
  48.         if(con == 2){
  49.             float cm;
  50.             printf("What is the distance in Centimetres? \n");
  51.             scanf("%f", &cm);
  52.         float in = (cm * 2.54);
  53.         printf("%.2f Centimetres is equal to %.2f Inches. \n", cm, in);
  54.         }
  55.     // Feet to Meters
  56.         if(con == 3){
  57.             float ft;
  58.             printf("What is the distance in feet? \n");
  59.             scanf("%f", &ft);
  60.         float m = (ft / 3.2808);
  61.         printf("%.2f feet is equal to %.2f meters. \n", ft, m);
  62.         }
  63.     // Meters to Feet
  64.         if(con == 4){
  65.             float m;
  66.             printf("What is the distance in meters? \n");
  67.             scanf("%f", &m);
  68.         float ft = (* 3.2808);
  69.         printf("%.2f meters is equal to %.2f feet. \n", m, ft);
  70.         }
  71.     }
  72.     return 0;
  73. }


Learn More :