• Breaking News

    A package for professionals

    Simple Calculator with If Else or Nested If Else in C Programing


    Simple Calculator with If Else in C Programming is one of the very good practices for nested if else.




    Program Explained(Logic):

    In this program, the main Logic of Do While Loop is to get inputs and do calculations as many times as required.
    And loop will terminate only when 'n' is Entered by the user. 

    Source Code:



    #include <stdio.h>
    #include<stdlib.h>
    int main(){    
    float x,y;    
    char operator,again;    
    do{    
    printf("Enter two numbers\n");    
    scanf("%f %f",&x,&y);    
    printf("Enter + to add\nOr Enter - to subtract\nOr Enter / to  Divide\nOr Enter * to Multiply\n");    
    fflush(stdin);  
    scanf("%c",&operator);    
    if (operator=='+')    
    {
           printf("\nSum=%f\n",x+y);
     }
      else if (operator=='-')    
    {
          printf("\nDiffrence=%f\n",x-y);
     }  
      else if (operator=='/')    
    {
          printf("\nDivision=%f\n",x/y);
     }   
     else if (operator=='*')   
     {
          printf("\nMultiplication=%f\n",x*y);
      }   
     else    
    {
          printf("\nInvalid Entry");
     } 
       printf("press y to again use it and n to exit");  
      scanf("%c",&again); 
      } while(again=='y'&& again!='n');    
    printf("%c",again);  
    getchar();
    return 0;
    }

    Note:

    Any Question!!??
    "Feel Free To Ask In Comments"
    Like and Share or Follow us on Facebook and Instagram for more Programs Codes ;).
    Email Us or inbox us to get Your Programs done :) 

    13 comments:

    1. Can you post a code about tabulating system using C Language. THANK YOU!

      ReplyDelete
    2. Write a Java program named “SimpleCalculator”. The flowchart of the SimpleCalcuator
      program is given as below. The program will ask the user to input two double type values
      (i.e. num1 and num2) and one char (i.e., op) by using the command line. Then the
      program will compare op with four possible calculators (i.e., ‘+’, ‘-‘, ‘*’, and ‘/’) by using the
      nested if…else statements, and output the calculation result of num1 op num2.

      ReplyDelete
    3. Whenever x<y and the operation goes like 4-6 the answer i get back is zero

      ReplyDelete
    4. Could you please make a code to create a calculator that includes (+ - × ÷ mode power fibonacci and factorial) with an exit statement and welcome statement

      ReplyDelete
    5. if we press y it does not run again....

      ReplyDelete
    6. printf("Sum= %f", a+b);
      }
      why he doesn't let me enter the operator and end the program

      ReplyDelete
    7. It isn't a good idea to use a payday loan on a regular basis. In the event that you endlessly prolong your repayment date and borrow often towards your subsequent paycheck, it could run you a good amount of money. However, it is just as sensible to decide on payday loans as they can be swiftly approved exactly the same day you put in your loan application form. You can contact Mr Pedro  loan offer because my payday loan was very fast to proceed, email  pedroloanss@gmail.com to request any kind of loans.

      ReplyDelete
    8. I DO NOT UNDERSTAND WHAT THE "FFLUSH(STDIN)" MEAN I DID IT ALMOST THE SAME AS YOU DID EXCEPT FROM THE "FFLUSH(STDIN)" THING.
      I WOULD LIKE FOR HELP WITH THIS PLEASE.

      ReplyDelete
    9. This is my first code https://www.sitesbay.com/program/c-program-for-calculator

      ReplyDelete
    10. Can we create a fuction without operators like +,×,÷,- and using variables in place of it

      ReplyDelete

    Our Aim

    About