some conversions

// 1kg = 2.205 pounds
// 1km = o.621 mile
// 1 foot = 12 inch
// 1 meter = 3.280 foot
// 1 inch = 2.54 cm

#include <stdio.h>
int main()
{
    char input;
    float quantity,result;
    float kgtopound=2.205;
    float kmtomile=0.621;
    float foottoinch=12;
    float mtofoot=3.280;
    float inchtocm=2.54;
    while (1)
        {
            printf("enter q to quiet\n    1.kg to pound \n    2.km to mile \n    3.foot to inch\n    4.m to foot\n    5.inch to cm\n");

            scanf(" %c",&input);
            switch(input)
            {
                case 'q':
                printf("thanks for using");
                goto end;
                break;

                case '1':
                printf("enter no to convert kg to pound:\n");
                scanf("%f",&quantity);
                result=quantity*kgtopound;
                printf("%.3f kg = %.3f pound\n\n",quantity,result);
                break;

                case '2':
                printf("enter no to convert km to mile:\n");
                scanf("%f",&quantity);
                result=quantity*kmtomile;
                printf("%.3f km = %.3f mile\n\n",quantity,result);
                break;

                case '3':
                printf("enter no to convert foot to inch:\n");
                scanf("%f",&quantity);
                result=quantity*foottoinch;
                printf("%.3f foot = %.3f inch\n\n",quantity,result);
                break;

                case '4':
                printf("enter no to convert m to foot:\n");
                scanf("%f",&quantity);
                result=quantity*mtofoot;
                printf("%.3f m = %.3f foot\n\n",quantity,result);
                break;

                case '5':
                printf("enter no to convert inch to cm:\n");
                scanf("%f",&quantity);
                result=quantity*inchtocm;
                printf("%.3f inch = %.3f cm\n\n",quantity,result);
                break;

                default:
                printf("pleas enter a valid character\n\n");

            }
        }
    end:

    return 0;
}

Comments

Popular posts from this blog

Steps taken by a compiler to execute a C program

Tokens in C

Variables and Data Types in C