do-while loop



QUESTION: 
conversion with else if case in do-while loop 
kilometer to meter *1000
meter to centimeter *100
cm to mm *10
F = 5/9*C+32
K = C + 273
f = 1.8*(k-273)+32


#include <stdio.h>
#include <conio.h>
void main()
{
    int a;
    float b;
    char ch;
    do
    {
        /* code */

        printf("select the option to convert\n");
        printf("1. kilometer to meter\n");
        printf("2. meter to centimeter\n");
        printf("3. cm to mm\n");
        printf("4. celsius to Fahrenheit \n");
        printf("5. celsius to kelvin\n");
        printf("6. kelvin to Fahrenheit\n");
        printf("enter a number to convert\n");
        scanf("%d", &a);
        if (a == 1)
        {
            printf("a. kilometer to meter\n");
            scanf("%f", &b);
            printf("%f m\n"b * 1000);
        }
        else if (a == 2)
        {
            printf("b. meter to centimeter\n");
            scanf("%f", &b);
            printf("%f cm\n"b * 100);
        }
        else if (a == 3)
        {
            printf("c. cm to mm\n");
            scanf("%f", &b);
            printf("%f m\n"b * 10);
        }
        else if (a == 4)
        {
            printf("d.  celsius to Fahrenheit\n");
            scanf("%f", &b);
            printf(" %f f \n"b * 9 / 5 + 32);
        }
        else if (a == 5)
        {
            printf("celsius to kelvin: \n");
            scanf("%f", &b);
            printf(" %f k\n"273 + b);
        }
        else if (a == 6)
        {
            printf("f. kelvin to Fahrenheit\n");
            scanf("%f", &b);
            printf(" %f f\n"1.8 * (b - 273) + 32);
        }

        else
        {
            printf("please try again!");
        }
        printf("press q to exti the code\n");
        scanf("%c", &ch);
    } while (ch != 'q');
}

OUTPUT
select the option to convert
1. kilometer to meter
2. meter to centimeter
3. cm to mm
4. celsius to Fahrenheit
5. celsius to kelvin
6. kelvin to Fahrenheit
enter a number to convert
3
c. cm to mm
100
1000.000000 m
press q to exit the code
select the option to convert
1. kilometer to meter
2. meter to centimeter
3. cm to mm
4. celsius to Fahrenheit
5. celsius to kelvin
6. kelvin to Fahrenheit
enter a number to convert
q
c. cm to mm
1000.000000 m
press q to exit the code

Follow our page for regular updates.

0 Comments