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.

Functions Basic with Switch statement

Thursday, May 19, 2011

#include <iostream.h>

float f_to_c(float);
float c_to_f(float);
int main ()
{
    int a=0;
    char x=' ';
    cout <<"Enter  What You Want To Do 'f for FAHRENHEIT TO CELSIUS and c for CELCIUS TO FAHRENHEIT  : ";
    cin >> x;
    switch (x)
    {
        case 'f' :
            cout <<"\nEnter Fahrenheit Temprature : ";
            cin >> a;
            cout <<f_to_c(a);
            break;
        case 'c' :
            cout <<"\nEnter Celsius Temprature : ";
            cin >> a;
            cout <<c_to_f(a);
            break;
        default :
            cout <<"\n\n WRONG ENTRY";

    }
    return 0;
}
float f_to_c(float y)
{
    y=(y-32)*(5/9);
    return y;
}
float c_to_f(float z)
{
    z=32+(z*(9/5));
    return z;
}