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(Area of Circle,Square and Rectangle)

Wednesday, May 18, 2011

#include <iostream.h>
#include <conio.h>
int main ()
{
    clrscr ();
    float r=0;   //for radius
    float w=0;   //for width
    float l=0;   //for length
    float z=0;  //for storing areas
    char area=' ';  //for users choice
    cout <<"Enter The Letter According To Menu\n";
    cout <<" s To Calculate Area Of Squre \n r To Calculate Area Of Rectangle \n c  To Calculate Area Of Circle \n =  ";
    cin >>area;
    switch (area)
    {
        case 's' :
            cout <<"\n Enter Length Of The Side : ";
            cin >> l;
            z=l*l;
            cout <<"\n The Area Of The Squre Is : " << z;
            break;
        case 'r' :
            cout <<"\n Enter The  Length : ";
            cin >> l;
            cout <<"\n Enter The Width : ";
            cin >> w;
            z=l*w;
            cout <<"\n The Area Of The Rectangle Is : " << z;
            break;
        case 'c' :
            cout <<"\n Enter The Radius Of THe Circle : ";
            cin >> r;
            z=3.14*(r*r);
            cout <<"\n The Area Of Circle Is : " << z;
            break;
        }
    getch();
    return 0;
}