Welcome

Hi! This blog is for beginners of c++ and java .You can check and pick codes for your programming assignments. This will also help you to understand the concepts of these programming languages. Its all about programming.

Switch statement Practice(Unit Convertor)

Wednesday, May 18, 2011

#include <iostream.h>
#include <conio.h>
int main ()
{
    clrscr ();
    float cm=0;
    float inch;
    float feet=0;
    float x=0;
    char function=' ';
    cout <<"    Wellcome To The Unit Converter In C++ ";
    cout <<"\n Enter The character According To Menu \n";
    cout <<"\n 'a' For cm To Inches \n\n 'b' For Inches To cm \n\n 'c' For Feet TO cm \n\n 'd' For cm TO Feet \n\n 'e' For Feet To Inches \n\n 'f' For Inches To Feet \n\n ONLY SMALL LETTERS ARE ACCEPTED\n\n = "; // menu for user
    cin >>function;
    switch (function)
    {
        case 'a' :
            cout <<"\n Enter centimeters : ";
            cin >>cm;
            x=cm/2.5;
            cout <<"\n Inches = "<< x <<endl;
            break;
        case 'b' :
            cout <<"\n Enter Inches : ";
            cin >>inch;
            x=inch*2.5;
            cout <<"\n CM = "<< x <<endl;
            break;
        case 'c' :
            cout <<"\n Enter Feet : ";
            cin >>feet;
            x=feet*30;
            cout <<"\n CM = " << x <<endl;
            break;
        case 'd' :
            cout <<"\n Enter Centimeters : ";
            cin >>cm;
            x=cm/30;
            cout <<"\n FEET = " << x <<endl;
            break;
        case 'e' :
            cout <<"\n Enter FEET : ";
            cin >>feet;
            x=feet*12;
            cout <<"\n INCHES = " << x <<endl;
            break;
        case 'f' :
            cout <<"\n Enter INCHES : ";
            cin >>inch;
            x=inch/12;
            cout <<"\n FEET = " << x <<endl;
            break;
    }
    getch();
    return 0;
}