How to make a simple calculator using C program

#include <stdio.h>
int main (void)
{
    char x,a,s,m,d;
    double y,z;
    printf("Please Select The Character\nfor addition  press 
a\nfor subtraction press s\nfor Division  press d\nfor 
Multiplication  press m\n");
    scanf("%c",&x);
    if(x=='a')
    {
        printf("Enter the first number: ");
        scanf("%lf",&y);
        printf("Enter the second number: ");
        scanf("%lf",&z);
        printf("The Addition is: %lf\n",y+z);
    }
    else if (x=='s')
    {
        printf("Enter the first number: ");
        scanf("%lf",&y);
        printf("Enter the second number: ");
        scanf("%lf",&z);     
        printf("The Subtraction is: %lf\n",y-z);
    }
    else if (x=='d')
    {
        printf("Enter the first number: "); 
        scanf("%lf",&y);
        printf("Enter the second number: ");
        scanf("%lf",&z);     
        printf("The Division is: %lf\n",y/z);
    }
    else if (x=='m')
    {
        printf("Enter the first number: "); 
        scanf("%lf",&y);
        printf("Enter the second number: ");
        scanf("%lf",&z);     
        printf("The Multiplication is: %lf\n",y*z);
    }
    else 
    {
         printf("You entered the wrong Character :(\n");
    }
    system("pause");
    return 0;
}
 

0 comments:

Post a Comment