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.

If Else Practice(Calculator with if else Statement)

Wednesday, May 18, 2011

#include <iostream.h>
#include <conio.h>
int main ()
{
    clrscr();
    float fn,sn;  //declaration for users input.
    float x;  //declaration for answer.
    float c,a=1,s=2,m=3,d=4;  //declaration "c" for user input and others are for +,-,*,/.
    cout <<"WELLCOM TO CALCULATOR IN C++" <<endl;
    cout <<"Enter First Number : ";
    cin >> fn;  //first number
    cout <<"\n Enter Opration Sign That You Want To Perform According To Menu" <<endl;
    cout <<"   MENU \n 1 Is For Addition \n 2 Is For Subtraction \n 3 Is For Multiplacation \n 4 Is For Division " <<endl;  //menu
    cout <<" OPRATION SIGN = ";
    cin >> c;
    cout <<"\nEnter Your Scond Number : ";
    cin >> sn;  //scond number
    cout <<endl;
    if (c==a)
    {
        x=fn+sn;
        cout <<" The Sum Is = "<< x <<endl;
    }
    else if (c==s)
    {
        x=fn-sn;
        cout <<"The Difference Is = "<< x <<endl;
    }
    else if (c==m)
    {
        x=fn*sn;
        cout <<" The Multiplacation Is = "<< x <<endl;
    }
    else if (c==d)
    {
        x=fn/sn;
        cout <<"The Division Is = "<< x <<endl;
    }
    getch();
    return 0;
}