Monday, 10 October 2011

10-10-2011 A Very Simple Calculator


/*Can say this program a simple Calculator*/
#include <stdio.h>
#include <conio.h>
int main()
{
   
    int dig1 = 0 , dig2 = 0 , opert;
    /*Declaring veriables in float for division operation*/
       float dig1f = 0, dig2f = 0;
    while (opert != 5)
        {
            printf("Please enter first digit: ");
            scanf("%d",&dig1);
            printf("\nPlease enter 2nd the digit: ");
            scanf("%d",&dig2);
            /*assigning same values to float variables*/
                     dig1f = dig1;
                     dig2f = dig2;
           
                     /*Showing Instructions*/
                     printf("\n\n\t\tInstructions\n");
            printf("\n______________________________________________\n");
            printf("\nTo add both digits enter 1\n");
            printf("\nTo subtract 2nd digit from first enter 2\n");
            printf("\nto multiply both digits enter 3\n");
            printf("\nTo divide first digit by 2nd enter 4\n");
            printf("\nTo quit enter 5\n\n");
           
                     /*Taking input for operation*/
                     scanf("%d",&opert);
                     /*Printing results*/
                     switch (opert)
            {
                case 1:
                     printf("\n\n%d + %d = %d\n\n\n",dig1, dig2, dig1 + dig2);
                     break;
                case 2: 
                     printf("\n\n%d - %d = %d\n\n\n",dig1, dig2, dig1 - dig2);
                     break;
                case 3:    
                     printf("\n\n%d x %d = %d\n\n\n",dig1, dig2,dig1 * dig2);
                     break;
                case 4:    
                     printf("\n\n%f / %f = %f\n\n\n",dig1f, dig2f, dig1f / dig2f);
                     break;
                
            }
                     /*rerunning the loop to rerun program*/
            continue;
        }   
    getche();
    return 0;
}

No comments:

Post a Comment