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:
- #include <stdio.h>
- #include <stdlib.h>
- /* README
- A simple conversion program
- Coded by SmakGezgo
- */
- int main()
- {
- // Main program select
- int list;
- int con;
- printf("Select a list:\n 1. Temperature converter\n 2. Distance converter\n");
- scanf( "%d", &list);
- // Temperature conversion list
- if(list == 1){
- printf("Select a converter:\n 1. Celsius to Fahrenheit\n 2. Fahrenheit to Celsius\n");
- scanf( "%d", &con);
- // Fahrenhiet to Celsius
- if(con == 1){
- int cel;
- printf("What is the degrees in Celsius? \n");
- scanf("%d", &cel);
- int fah = (cel * 1.8) + 32;
- printf("%d degrees Celsius is equal to %d degrees Fahrenheit. \n", cel, fah);
- }
- // Celsius to Fahrenhiet
- else if(con == 2){
- int fah;
- printf("What is the degrees in Fahrenheit? \n");
- scanf("%d", &fah);
- int cel = (fah - 32) * .5556;
- printf("%d degrees Fahrenheit is equal to %d degrees Celsius. \n", fah, cel);
- }
- }
- // Distance conversion list
- if(list == 2){
- 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");
- scanf( "%d", &con);
- // Inches to Centimeters
- if(con == 1){
- float in;
- printf("What is the distance in Inches? \n");
- scanf("%f", &in);
- float cm = (in * .39);
- printf("%.2f Inches is equal to %.2f Centimetres. \n", in, cm);
- }
- // Centimeters to Inches
- if(con == 2){
- float cm;
- printf("What is the distance in Centimetres? \n");
- scanf("%f", &cm);
- float in = (cm * 2.54);
- printf("%.2f Centimetres is equal to %.2f Inches. \n", cm, in);
- }
- // Feet to Meters
- if(con == 3){
- float ft;
- printf("What is the distance in feet? \n");
- scanf("%f", &ft);
- float m = (ft / 3.2808);
- printf("%.2f feet is equal to %.2f meters. \n", ft, m);
- }
- // Meters to Feet
- if(con == 4){
- float m;
- printf("What is the distance in meters? \n");
- scanf("%f", &m);
- float ft = (m * 3.2808);
- printf("%.2f meters is equal to %.2f feet. \n", m, ft);
- }
- }
- return 0;
- }